Esempio n. 1
0
        protected override void HandleTtsOffsetEndFrame(SaiTtsFrameOffsetEnd offsetEndFrame)
        {
            // 收到OffsetEnd,停止Tres_start计时器
            LogUtility.Info(string.Format("{0}: 收到OffsetEnd报文,停止Tres_start计时器。", this.Context.RsspEP.ID));
            this.Context.StopHandshakeTimer();

            if (offsetEndFrame.Valid)
            {
                LogUtility.Info(string.Format("{0}: 时钟偏移估算结果有效,SAI层连接成功。", this.Context.RsspEP.ID));
            }
            else
            {
                LogUtility.Info(string.Format("{0}: 时钟偏移估算结果无效,无法建立SAI连接。", this.Context.RsspEP.ID));
            }

            //
            this.Context.Connected = offsetEndFrame.Valid;

            if (!offsetEndFrame.Valid)
            {
                throw new Exception(string.Format("{0}: 时钟偏移估算结果无效,无法建立SAI连接。", this.Context.RsspEP.ID));
            }

            // 更新状态。
            this.Context.CurrentState = new TtsConnectedState(this);
        }
Esempio n. 2
0
        public static SaiFrame Parse(byte[] bytes)
        {
            SaiFrame theFrame = null;

            var theFrameType = (SaiFrameType)bytes[0];

            if (theFrameType == SaiFrameType.TTS_OffsetStart)
            {
                theFrame = new SaiTtsFrameOffsetStart();
            }
            else if (theFrameType == SaiFrameType.TTS_OffsetAnswer1)
            {
                theFrame = new SaiTtsFrameOffsetAnswer1();
            }
            else if (theFrameType == SaiFrameType.TTS_OffsetAnswer2)
            {
                theFrame = new SaiTtsFrameOffsetAnswer2();
            }
            else if (theFrameType == SaiFrameType.TTS_OffsetEstimate)
            {
                theFrame = new SaiTtsFrameEstimate();
            }
            else if (theFrameType == SaiFrameType.TTS_OffsetEnd)
            {
                theFrame = new SaiTtsFrameOffsetEnd();
            }
            else if (theFrameType == SaiFrameType.TTS_AppData)
            {
                theFrame = new SaiTtsFrameAppData();
            }
            else if (theFrameType == SaiFrameType.EC_Start)
            {
                theFrame = new SaiEcFrameStart();
            }
            else if (theFrameType == SaiFrameType.EC_AppData)
            {
                theFrame = new SaiEcFrameApplication();
            }
            else if (theFrameType == SaiFrameType.EC_AppDataAskForAck)
            {
                theFrame = new SaiEcFrameAskForAck();
            }
            else if (theFrameType == SaiFrameType.EC_AppDataAcknowlegment)
            {
                theFrame = new SaiEcFrameAcknowlegment();
            }
            else
            {
                throw new InvalidOperationException(string.Format("无法解析指定的Sai帧,不可识别的类型{0}。", theFrameType));
            }

            theFrame.ParseBytes(bytes);

            return(theFrame);
        }
Esempio n. 3
0
        public void Test1()
        {
            var frameInital = new SaiTtsFrameOffsetEnd();

            frameInital.SequenceNo                = 100;
            frameInital.SenderTimestamp           = 1000;
            frameInital.SenderLastRecvTimestamp   = 900;
            frameInital.ReceiverLastSendTimestamp = 800;
            frameInital.Valid = true;

            var bytes = frameInital.GetBytes();

            var actual = SaiFrame.Parse(bytes) as SaiTtsFrameOffsetEnd;

            Assert.AreEqual(frameInital.FrameType, actual.FrameType);
            Assert.AreEqual(frameInital.SequenceNo, actual.SequenceNo);
            Assert.AreEqual(frameInital.SenderTimestamp, actual.SenderTimestamp);
            Assert.AreEqual(frameInital.SenderLastRecvTimestamp, actual.SenderLastRecvTimestamp);
            Assert.AreEqual(frameInital.ReceiverLastSendTimestamp, actual.ReceiverLastSendTimestamp);
            Assert.AreEqual(frameInital.Valid, actual.Valid);
        }
Esempio n. 4
0
        protected override void HandleTtsEstimateFrame(SaiTtsFrameEstimate estimateFrame)
        {
            // 收到OffsetEst,停止计时器
            LogUtility.Info(string.Format("{0}: 收到OffsetEst报文,停止Tint_start计时器。", this.Context.RsspEP.ID));
            this.Context.StopHandshakeTimer();

            // 更新时间戳
            this.Calculator.ResMinOffset = estimateFrame.OffsetMin;
            this.Calculator.ResMaxOffset = estimateFrame.OffsetMax;

            // 检查估算值
            var valid = this.Calculator.IsEstimationValid();

            // 更新连接状态。
            this.Context.Connected = valid;

            // 发送OffsetEnd。
            var seq            = (ushort)this.Context.SeqNoManager.GetAndUpdateSendSeq();
            var offsetEndFrame = new SaiTtsFrameOffsetEnd(seq,
                                                          TripleTimestamp.CurrentTimestamp, TTS.RemoteLastSendTimestamp, TTS.LocalLastRecvTimeStamp, valid);

            this.Context.NextLayer.SendUserData(offsetEndFrame.GetBytes());

            //
            if (valid)
            {
                LogUtility.Info(string.Format("{0}: 发送OffsetEnd,时钟偏移验证通过,SAI层连接成功。", this.Context.RsspEP.ID));
            }
            else
            {
                throw new Exception(string.Format("{0}: 时钟偏移估算无效,SAI层连接失败。", this.Context.RsspEP.ID));
            }

            // 更新状态。
            this.Context.CurrentState = new TtsConnectedState(this);
        }
Esempio n. 5
0
 protected virtual void HandleTtsOffsetEndFrame(SaiTtsFrameOffsetEnd frame)
 {
     LogUtility.Error(string.Format("{0}: {1}.{2} not implement!",
                                    this.Context.RsspEP.ID, this.GetType().Name,
                                    new StackFrame(0).GetMethod().Name.Split('.').Last()));
 }