Beispiel #1
0
        // Stops the replay and goes back to time 0
        public void Stop()
        {
            if (CurrentState == State.Stoped)
            {
                return;
            }

            if (cancelToken != null && cancelToken.CanBeCanceled)
            {
                cancelSource.Cancel();
                runningJob.Wait();
            }

            // Clean Senders
            CloseSenders();

            eventTimer?.Dispose();
            eventTimer = null;

            CurrentState = State.Stoped;
            StatusEvent?.Invoke(CurrentState);

            foreach (var k in _dataRate.Keys.ToList())
            {
                _dataRate[k] = 0;
            }
            DataRateEvent?.Invoke(_dataRate);

            ProgressEvent?.Invoke(0);
        }
Beispiel #2
0
        //public UDPSender(ulong _ipport, bool onlyLocal, string _netcard = "")
        //{
        //    int[] ip =
        //    {
        //        (byte)(_ipport),(byte)(_ipport >> 8), (byte)(_ipport >> 16), (byte)(_ipport >> 24)
        //    };

        //    if (onlyLocal)
        //        ttl = 0;
        //    else
        //        ttl = 25;

        //    netcard = _netcard;
        //    networkIp = String.Format("{0}.{1}.{2}.{3}", ip[0], ip[1], ip[2], ip[3]);
        //    networkPort = (byte)(_ipport >> 32) | ((byte)(_ipport >> 40) << 8) | ((byte)(_ipport >> 48) << 16) | ((byte)(_ipport >> 56) << 24);

        //    isMulticast = HelperTools.IsMulticast(networkIp, out IPAddress ipAdrr);
        //}

        private void OnDataRate(object state)
        {
            float dataRateMpbsTX = (bytesAccumulatorTX * 8f) / 1048576; // Mpbs

            bytesAccumulatorTX = 0;

            DataRateEvent?.Invoke(ID, dataRateMpbsTX);
        }
Beispiel #3
0
 private void OnEventTimer(object state)
 {
     // Status event
     if (CurrentState == State.Playing)
     {
         // Datarate event
         DataRateEvent?.Invoke(_dataRate);
         //ProgressEvent?.Invoke((int)(replayTime / 1000000));
     }
 }
Beispiel #4
0
        private void OnEventTimer(object state)
        {
            // Write IDX
            WriteIdx();
            // Datarate event
            DataRateEvent?.Invoke(_dataRate);
            // Update Time
            secTime++;

            // Status event
            if (CurrentState == State.Recording)
            {
                ProgressEvent?.Invoke((float)(file.Position / 1048576.0), secTime);
            }
        }
Beispiel #5
0
        public void UnsubscribeEventHandlers()
        {
            if (DataReadySyncEvent != null)
            {
                foreach (var d in DataReadySyncEvent.GetInvocationList())
                {
                    DataReadySyncEvent -= (d as DataReadySyncDelegate);
                }
            }
            DataReadySyncEvent = null;

            if (DataReadyAsyncEvent != null)
            {
                foreach (var d in DataReadyAsyncEvent.GetInvocationList())
                {
                    DataReadyAsyncEvent -= (d as DataReadyAsyncDelegate);
                }
            }
            DataReadyAsyncEvent = null;

            if (ConnectionStateEvent != null)
            {
                foreach (var d in ConnectionStateEvent.GetInvocationList())
                {
                    ConnectionStateEvent -= (d as ConnectionStateDelegate);
                }
            }
            ConnectionStateEvent = null;

            if (DataRateEvent != null)
            {
                foreach (var d in DataRateEvent.GetInvocationList())
                {
                    DataRateEvent -= (d as DataRateDelegate);
                }
            }
            DataRateEvent = null;
        }
Beispiel #6
0
        private void RunReaderSenderProcessCallback(string _filePath, string _idxFilePath, CancellationToken token)
        {
            ulong ip;
            int   n_bytes = 0, size = 0;
            int   hashedID = 0;
            long  timeoffset = 0, waitTime = 0, nowTime = 0, time = 0;
            int   lastTimeStatusS = 0, timeStatusS = 0;

            // Increase timers resolution
            WinAPI.WinAPITime.TimeBeginPeriod(1);

            // Open file
            using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                if (has2UpdatePosition)
                {
                    file.Seek(newPosition, SeekOrigin.Begin);
                    has2UpdatePosition      = false;
                    resetTimeOffsetRequired = true;
                }

                while (!token.IsCancellationRequested)
                {
                    // Paused
                    if (CurrentState == State.Paused)
                    {
                        Thread.Sleep(500);
                    }
                    else
                    {
                        if ((n_bytes = file.Read(buffer, 0, HelperTools.headerSize)) == HelperTools.headerSize)
                        {
                            // Get fields
                            replayTime = time = BitConverter.ToInt64(buffer, 0);
                            hashedID   = BitConverter.ToInt32(buffer, 8);
                            ip         = BitConverter.ToUInt64(buffer, 12);
                            size       = BitConverter.ToInt32(buffer, 20);

                            // Update time in secs
                            timeStatusS = (int)(replayTime / 1000_000);

                            // Read Payload
                            n_bytes = file.Read(buffer, 0, size);

                            nowTime = HelperTools.GetLocalMicrosTime();

                            if (resetTimeOffsetRequired)
                            {
                                timeoffset = nowTime - time;
                                waitTime   = 0;
                                resetTimeOffsetRequired = false;
                            }
                            else
                            {
                                nowTime -= timeoffset;
                                waitTime = time - nowTime;
                                if (waitTime > 1000) // 1ms
                                {
                                    Thread.Sleep((int)(waitTime / 1000));
                                }
                            }

                            // Send
                            Send(hashedID, buffer, 0, n_bytes);

                            // Update Progress
                            if (timeStatusS != lastTimeStatusS)
                            {
                                ProgressEvent?.Invoke(timeStatusS);
                                lastTimeStatusS = timeStatusS;
                            }

                            if (has2UpdatePosition)
                            {
                                file.Seek(newPosition, SeekOrigin.Begin);
                                has2UpdatePosition      = false;
                                resetTimeOffsetRequired = true;
                            }
                        }
                        else
                        {
                            // End of File
                            cancelSource.Cancel();
                            // Update Stop Status
                            CurrentState = State.Stoped;
                            StatusEvent?.Invoke(CurrentState);
                            foreach (var k in _dataRate.Keys.ToList())
                            {
                                _dataRate[k] = 0;
                            }
                            DataRateEvent?.Invoke(_dataRate);
                            // rewind
                            Seek(0);
                            eventTimer.Dispose();
                            eventTimer = null;
                            ProgressEvent?.Invoke(0);
                        }
                    }
                }
            }
            WinAPI.WinAPITime.TimeEndPeriod(1);
        }
Beispiel #7
0
 public virtual void FireDataRateEvent(string ID, float dataRateMbpsRX, float dataRateMbpsTX)
 {
     DataRateEvent?.Invoke(ID, dataRateMbpsRX, dataRateMbpsTX);
 }