示例#1
0
        //When ReceiverClient events
        private void OnReceiverClientEvent(object sender, DataEventArgs e)
        {
            foreach (var track in e.Tracks)
            {
                // Look for track in list of tracks in airspace
                var   foundTrack      = _airCraftsInAirspaceList.Find(ByTag(track.Tag));
                Track trackToValidate = null;
                // If already in list - update speed and coordinates.
                if (foundTrack != null)
                {
                    double trackSeconds      = (track.Time.Minute * 60) + track.Time.Second;
                    double foundTrackSeconds = (foundTrack.Time.Minute * 60) + foundTrack.Time.Second;

                    // Workaround
                    TimeSpan differenceTime = track.Time.Subtract(foundTrack.Time);


                    var velocity = _trackCalculator.CalculateVelocity(foundTrack.XCoordinate, track.XCoordinate,
                                                                      foundTrack.YCoordinate, track.YCoordinate,
                                                                      foundTrack.Altitude, track.Altitude,
                                                                      0, differenceTime.TotalSeconds);

                    var compassCourse = _trackCalculator.CalculateCourse(foundTrack.XCoordinate, track.XCoordinate,
                                                                         foundTrack.YCoordinate, track.YCoordinate);

                    var newTrack = new Track(foundTrack.Tag, track.XCoordinate, track.YCoordinate,
                                             track.Altitude, track.Time, velocity, compassCourse);

                    _airCraftsInAirspaceList.Remove(foundTrack);
                    _airCraftsInAirspaceList.Add(newTrack);
                    trackToValidate = newTrack;
                }

                // If not in list - add it    This should be tested - intellisense says expression is always true
                else if (foundTrack == null)
                {
                    _airCraftsInAirspaceList.Add(track);
                    trackToValidate = track;
                }

                // If outside airspace, remove it.
                bool inAirSpace = _monitoredAirspace.ValidateAirspace(trackToValidate);
                if (!inAirSpace)
                {
                    _airCraftsInAirspaceList.Remove(trackToValidate);
                }
            }

            // Pass on Tracks in monitored airspace if not empty
            if (_airCraftsInAirspaceList.Count != 0)
            {
                var args = new ATMSEventArgs();
                args.Tracks = _airCraftsInAirspaceList;

                // Raise event if somebody has "subscribed" to it
                DataReady?.Invoke(this, args);
            }
        }
示例#2
0
        public PipelineReader(System.Management.Automation.Runspaces.PipelineReader <T> pipelineReader)
        {
            this.pipelineReader = pipelineReader;

            pipelineReader.DataReady += (sender, e) =>
            {
                DataReady?.Invoke(sender, e);
            };
        }
示例#3
0
        void _serial_PortDataReveived(Object sender, SerialDataReceivedEventArgs e)
        {
            SerialPort _Dataport = (SerialPort)sender;

            Byte[] ReadData = new Byte[_Dataport.BytesToRead];
            for (int i = 0; i < _Dataport.BytesToRead; i++)
            {
                ReadData[i] = (byte)_Dataport.ReadByte();
            }
            this.LastreadData = ReadData;
            DataReady?.Invoke(this, e);
        }
示例#4
0
        public async void BeginLoad()
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("http://www.google.com");
            HttpResponseMessage msg = await client.GetAsync("");

            string content = await msg.Content.ReadAsStringAsync();

            Data = content;
            DataReady?.Invoke(this, EventArgs.Empty);
        }
示例#5
0
        void OnDataReady(object sender, EventArgs e)
        {
            UT60EPacket package = (e as UT60EPackageReceivedEventArgs).package;
            IUT60EData  data    = package.Parse();

            if (data == null)
            {
                parse_error_count += 1;
            }
            else if (data.Unit == unit)
            {
                data_packages.Add(data);
            }
            else
            {
                data = null;
            }
            DataReady.Invoke(this, new UT60EDataReadyEventArgs(data));
        }
示例#6
0
        public async void Get_Json(string company_name)
        {
            string              base_url = "http://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=";
            string              Json_Url = String.Concat(base_url + company_name + "&apikey=");
            HttpClient          client   = new HttpClient();
            HttpResponseMessage response = await client.GetAsync(Json_Url);

            data = await response.Content.ReadAsStringAsync();


            data = data.Replace("1. open", "open");
            data = data.Replace("2. high", "high");
            data = data.Replace("3. low", "low");
            data = data.Replace("4. close", "close");
            data = data.Replace("5. volume", "volume");
            File.WriteAllText(Json_FilePath, data);
            _stockvalues = Parse_Json();
            //check if data is ready
            DataReady?.Invoke(this, EventArgs.Empty);

            Console.WriteLine($"file saved to {Json_FilePath}.");
        }
示例#7
0
        private void calculateTransform(ChannelData channel)
        {
            for (int i = 0; i < transformLength; i++)
            {
                channel.Complex[i] = new Complex
                {
                    X = channel.InputHistory[i] * window[i],
                    Y = 0f
                };
            }

            transformProvider.FFT(true, m, channel.Complex);

            var e = new FourierTransformEventArgs(
                transformLength,
                channel.Index,
                channel.Complex);

            if (DataReady != null)
            {
                DataReady.Invoke(this, e);
            }
        }
 public void SetDataReady(int index)
 {
     DataReady?.Invoke(index);
 }
 private void OnDataReady(DataReadyEventArgs e) => DataReady?.Invoke(this, e);
示例#10
0
 protected virtual void OnDataReady(string path, long size, int count, string name)
 {
     DataReady?.Invoke(path, size, count, name);
 }
示例#11
0
        /// <summary>
        /// It will connect on the server with given IP and Port then listens on it. Use it in the thread/task
        /// </summary>
        /// <param name="ip">Server IP</param>
        /// <param name="port">Server Port</param>
        /// <param name="endBytesIdentifier">
        /// This identifies the end packet once receive these bytes it will push the packet. If null
        /// then it pushes as it receives
        /// </param>
        /// <param name="connectionTimeoutMs"></param>
        /// <param name="receiveTimeOut"></param>
        /// <param name="transmissionTimeout"></param>
        /// <returns>Connection Status</returns>
        public bool Connect(string ip, int port, byte[] endBytesIdentifier = null, int connectionTimeoutMs = 2000, int receiveTimeOut = 1000, int transmissionTimeout = 1000)
        {
            if (endBytesIdentifier != null)
            {
                endBytesIdentifier = endBytesIdentifier.Reverse().ToArray();
            }
            if (IsConnected)
            {
                return(IsConnected);
            }
            clientTcp = new TcpClient()
            {
                ReceiveTimeout = receiveTimeOut, SendTimeout = transmissionTimeout
            };

            try
            {
                IAsyncResult result  = clientTcp.BeginConnect(ip, port, null, null);
                bool         success = result.AsyncWaitHandle.WaitOne(connectionTimeoutMs, true);
                IsConnected = clientTcp.Connected;
                if (!IsConnected)
                {
                    return(IsConnected);
                }
                Port = port;
                Ip   = ip;
            }
            catch (Exception ex)
            {
                ExceptionHandler?.Invoke(this, ex);
                return(IsConnected);
            }

            try
            {
                stream = clientTcp.GetStream();
                ReplyPacket replyPacket = new ReplyPacket()
                {
                    IsSentAndReplyReceived = true, IPSender = ip
                };
                IsConnected = true;

                List <byte> completePacket = new List <byte>();
                Task.Run(async() =>
                {
                    while (clientTcp.Connected)
                    {
                        if (!IsConnected)
                        {
                            break;
                        }

                        if (!stream.DataAvailable)
                        {
                            await Task.Delay(1).ConfigureAwait(false);
                        }
                        else
                        {
                            try
                            {
                                byte[] packet = new byte[clientTcp.Available];
                                await stream.ReadAsync(packet, 0, packet.Length).ConfigureAwait(false);
                                completePacket.AddRange(packet);
                                int lenth = completePacket.Count;
                                if (endBytesIdentifier != null)
                                {
                                    //this will flush any data that was there before connecting to the software
                                    //if (lenth > 5000) { completePacket.Clear(); continue; }
                                    if (completePacket.Count > endBytesIdentifier.Length)
                                    {
                                        bool isPacketEndIdentified = false;
                                        for (int i = 0; i < endBytesIdentifier.Length; i++)
                                        {
                                            if (completePacket[lenth - (i + 1)] == endBytesIdentifier[i])
                                            {
                                                isPacketEndIdentified = true;
                                            }
                                            else
                                            {
                                                isPacketEndIdentified = false;
                                                break;
                                            }
                                        }
                                        if (isPacketEndIdentified)
                                        {
                                            replyPacket.SetReply(completePacket);
                                            DataReady?.Invoke(this, replyPacket);
                                            completePacket.Clear();
                                        }
                                    }
                                }
                                else
                                {
                                    replyPacket.SetReply(completePacket);
                                    DataReady?.Invoke(this, replyPacket);
                                    completePacket.Clear();
                                }
                            }
                            catch (Exception ex)
                            {
                                ExceptionHandler?.Invoke(this, ex);
                            }
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                ExceptionHandler?.Invoke(this, ex);
            }

            return(IsConnected);
        }
示例#12
0
 protected virtual void OnDataReady(DataReadyEventArgs e)
 {
     DataReady?.Invoke(this, e);
 }
示例#13
0
 /// <summary>
 /// Transmit a packet to a remote host
 /// </summary>
 /// <param name="destination">The host to transmit to</param>
 /// <param name="buffer">The buffer to transmit</param>
 /// <param name="length">The length of the data to transfer</param>
 internal void Transmit(IPEndPoint destination, byte[] buffer, int length)
 {
     DataReady?.Invoke(destination, buffer, length);
 }