コード例 #1
0
        public void Test1()
        {
            var frameInital = new SaiTtsFrameOffsetAnswer2();

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

            var bytes = frameInital.GetBytes();

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

            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);
        }
コード例 #2
0
        protected override void  HandleTtsOffsetAnswer1Frame(SaiTtsFrameOffsetAnswer1 answer1)
        {
            // 收到Answer1,停止计时器
            LogUtility.Info(string.Format("{0}: 收到的OffsetAnswer1,停止Tint_start计时器。", this.Context.RsspEP.ID));
            this.Context.StopHandshakeTimer();

            // 更新时间戳
            this.Calculator.InitTimestamp2 = this.TTS.LocalLastRecvTimeStamp;
            this.Calculator.ResTimestamp1  = answer1.SenderLastRecvTimestamp;
            this.Calculator.ResTimestamp2  = answer1.SenderTimestamp;

            // 发起方计算偏移
            this.Calculator.EstimateInitOffset();

            // 记录日志
            LogUtility.Info(string.Format("{0}: 发起方估算时钟偏移,OffsetMin = {1}, OffsetMax = {2}",
                                          this.Context.RsspEP.ID, this.Calculator.InitiatorMinOffset, this.Calculator.InitiatorMaxOffset));

            // 发送OffsetAnswer2报文
            var seq     = (ushort)this.Context.SeqNoManager.GetAndUpdateSendSeq();
            var answer2 = new SaiTtsFrameOffsetAnswer2(seq,
                                                       TripleTimestamp.CurrentTimestamp,
                                                       this.TTS.RemoteLastSendTimestamp,
                                                       this.TTS.LocalLastRecvTimeStamp);

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

            LogUtility.Info(string.Format("{0}: 发送OffsetAnswer2。", this.Context.RsspEP.ID));


            // 启动计时器,等待OffsetEst报文
            LogUtility.Info(string.Format("{0}: 启动Tint_start计时器,等待OffsetEst报文", this.Context.RsspEP.ID));
            this.Context.StartHandshakeTimer();

            // 更新状态。
            this.Context.CurrentState = new TtsWaitingforEstimateState(this);
        }