Ejemplo n.º 1
0
        /// <summary>
        /// Throws a socket exception only on initialization.  Once everything is up and running exceptions are handled internally.
        /// </summary>
        /// <param name="endpoint"></param>
        /// <param name="new_frame_callback"></param>
        /// <param name="should_cancel_callback">Called at 1 Hz</param>
        public static void Listen(
            IPEndPoint endpoint,
            FrameRecieved new_frame_callback    = null,
            ShouldCancel should_cancel_callback = null)
        {
            var framer = new VLP_16_Framer(new_frame_callback);

            VLP_16.Listen(
                endpoint,
                framer.RecievePacket,
                should_cancel_callback);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method won't return untill listener is done (canceled manually, or error).
        /// It returns the raw data packets sent by the VLP-16
        /// Throws a socket exception only on initialization.  Once everything is up and running exceptions are handled internally.
        /// </summary>
        /// <param name="endpoint">Where to listen for data</param>
        /// <param name="packet_recieved_callback">New data gets parsed, sent to this method.</param>
        /// <param name="should_cancel_callback">Hearbeat function, called at 1 Hz, can stop the velodyne listener</param>
        public static void Listen(
            IPEndPoint endpoint,
            PacketRecieved packet_recieved_callback = null,
            ShouldCancel should_cancel_callback     = null)
        {
            UdpClient cl = null;

            try
            {
                cl = new UdpClient(new IPEndPoint(IPAddress.Any, endpoint.Port));
                cl.Client.ReceiveTimeout    = 250; // .25 Seconds
                cl.Client.ReceiveBufferSize = 4096;

                Listen_(cl, packet_recieved_callback, should_cancel_callback); // This will only end when canceled
            }
            finally
            {
                if (cl != null)
                {
                    cl.Dispose();
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This constructor won't return untill listener is done (or error).
        /// It returns the raw data packets sent by the VLP-16
        /// Throws a socket exception only on initialization.  Once everything is up and running exceptions are handled internally.
        /// </summary>
        /// <param name="d"></param>
        /// <param name="packet_recieved_sync"></param>
        /// <param name="should_cancel_async">Called at 1 Hz</param>
        public VLP_16(
            IPEndPoint d,
            PacketRecieved packet_recieved_sync = null,
            ShouldCancel should_cancel_async    = null)
        {
            UdpClient cl = null;

            try
            {
                cl = new UdpClient(new IPEndPoint(d.Address, d.Port));
                cl.Client.ReceiveTimeout    = 250; // .25 Seconds
                cl.Client.ReceiveBufferSize = 4096;

                this.Listen(cl, packet_recieved_sync, should_cancel_async); // This will only end when canceled
            }
            finally
            {
                if (cl != null)
                {
                    cl.Dispose();
                }
            }
        }
Ejemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            ShouldCancel Cancel = PersistUnsavedChanges(true);

            if (Cancel == ShouldCancel.Yes)
            {
                return;
            }

            using (OpenFileDialog D = new OpenFileDialog())
            {
                D.Filter          = "Clang Tidy files|.clang-tidy";
                D.CheckPathExists = true;
                D.CheckFileExists = true;

                if (D.ShowDialog() == DialogResult.OK)
                {
                    PropertyChain_.Clear();
                    PropertyChain_ = ClangTidyConfigParser.ParseConfigurationChain(D.FileName);
                    textBox1.Text  = D.FileName;
                    reloadPropertyChain();
                }
            }
        }
Ejemplo n.º 5
0
        private static unsafe void Listen_(
            UdpClient cl,
            PacketRecieved packet_recieved_callback,
            ShouldCancel should_cancel_callback)
        {
            DateTime start           = DateTime.Now;
            int      elapsed_seconds = 0;

            int corrects     = 0;
            int incorrects   = 0;
            int timeouts     = 0;
            int socketerrors = 0;

            while (true)
            {
                try
                {
                    IPEndPoint iep  = null;
                    var        data = cl.Receive(ref iep);

                    if (data.Length == Packet.Raw._Size)
                    {
                        Packet p;
                        bool   valid;

                        fixed(byte *b = data)
                        p = new Packet(b, out valid);

                        if (valid)
                        {
                            corrects++;
                            packet_recieved_callback?.Invoke(p, iep);
                        }
                        else
                        {
                            incorrects--;
                        }
                    }
                    else
                    {
                        incorrects++;
                    }
                }
                catch (TimeoutException)
                {
                    timeouts++;
                }
                catch (SocketException)
                {
                    socketerrors++;
                }
                catch (Exception e)
                {
                    Logger.WriteException(typeof(VLP_16), "Listen", e);
                    incorrects++;
                }

                var now = DateTime.Now;
                if ((now - start).TotalSeconds > elapsed_seconds)
                {
                    elapsed_seconds++;

                    var st = new UpdateArgs();

                    st.Timeouts = timeouts;
                    st.PacketsReceivedCorrectly   = corrects;
                    st.PacketsReceivedIncorrectly = incorrects;
                    st.SocketErrors = socketerrors;

                    timeouts     = 0;
                    corrects     = 0;
                    incorrects   = 0;
                    socketerrors = 0;

                    if (should_cancel_callback != null)
                    {
                        if (should_cancel_callback(st))
                        {
                            return;
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private unsafe void Listen(
            UdpClient cl,
            PacketRecieved packet_recieved_sync,
            ShouldCancel should_cancel_async)
        {
            DateTime start           = DateTime.Now;
            int      elapsed_seconds = 0;

            int corrects     = 0;
            int incorrects   = 0;
            int timeouts     = 0;
            int socketerrors = 0;

            while (true)
            {
                try
                {
                    IPEndPoint iep  = null;
                    var        data = cl.Receive(ref iep);

                    if (data.Length == Packet.Raw._Size)
                    {
                        Packet p;
                        bool   valid;

                        fixed(byte *b = data)
                        p = new Packet(b, out valid);

                        if (valid)
                        {
                            corrects++;

                            if (packet_recieved_sync != null)
                            {
                                packet_recieved_sync(p, iep);
                            }
                        }
                        else
                        {
                            incorrects--;
                        }
                    }
                    else
                    {
                        incorrects++;
                    }
                }
                catch (TimeoutException)
                {
                    timeouts++;
                }
                catch (SocketException)
                {
                    socketerrors++;
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(this.GetType().FullName + ": " + e.ToString());
                    incorrects++;
                }

                var now = DateTime.Now;
                if ((now - start).TotalSeconds > elapsed_seconds)
                {
                    elapsed_seconds++;

                    var st = new UpdateArgs();

                    st.SocketErrors               = timeouts;
                    st.PacketsReceivedCorrectly   = corrects;
                    st.PacketsReceivedIncorrectly = incorrects;
                    st.SocketErrors               = socketerrors;

                    timeouts     = 0;
                    corrects     = 0;
                    incorrects   = 0;
                    socketerrors = 0;

                    if (should_cancel_async != null)
                    {
                        if (should_cancel_async(st))
                        {
                            return;
                        }
                    }
                }
            }
        }