Exemple #1
0
        /// <summary>
        /// 接收数据小块,进行解码和检查工作
        /// </summary>
        /// <param name="inBytes"></param>
        public void Receive(byte[] inBytes)
        {
            bool isReverse = false;
            byte preamble  = PREAMBLE_VALUE;

            if (isReverse)//这句话的作用是啥?
            {
                inBytes  = ByteSequence.Inverse(inBytes);
                preamble = REVERSE_PREAMBLE_VALUE;
            }

            //1)转换成二进制字符串,该数据在各个过程中将被改变
            ByteSequence.EnQuence(inBytes);
            //拼接上一过程留下的数据
            InsertAndEmpytyPreRemainedData();

            while (this.DataAquirement.ByteCount <= ByteSequence.Count)
            {
                var InputBytes = ByteSequence.DeQueue(this.DataAquirement.ByteCount);

                switch (this.DataAquirement.PositionState)
                {
                case DataPositionState.FindingPreamble:
                    int index = -1;
                    for (int i = 0; i < InputBytes.Count; i++)
                    {
                        if (InputBytes[i] == preamble)
                        {
                            index = i;
                            break;
                        }
                    }
                    //1.1 没有找到,则返回后7位作为下一字符的开头,继续搜索
                    if (index == -1)
                    {
                        this.PrevRemainedBytes = null;
                    }
                    //1.2 找到了,则解析,并转入下一个过程
                    else
                    {
                        this.CurrentFrame = new Rtcm3Frame(preamble);      //说明是新开始的头部

                        //如果后继字节不够,则重新来过
                        if (InputBytes.Count < index + 3)
                        {
                            //处理完一个帧啦,下一步进行第二帧处理
                            this.PrevRemainedBytes            = InputBytes.GetRange(index, InputBytes.Count - index);
                            this.DataAquirement.PositionState = DataPositionState.FindingPreamble;
                            this.DataAquirement.ByteCount     = 30;//一次预读取字符数量 bre
                            break;
                        }
                        ProcessPresamble(InputBytes, index);
                    }
                    break;

                case DataPositionState.ParsingContentData:    //5)已经找到了报文头部,接下来进行处理
                    this.CurrentFrame.AddContent(InputBytes);
                    this.DataAquirement.PositionState = Rtcm.DataPositionState.CheckingCrc;
                    this.DataAquirement.ByteCount     = 3;//一次预读取字符数量
                    break;

                case DataPositionState.CheckingCrc:
                    CheckCrs(isReverse, InputBytes);
                    break;

                default: break;
                }

                InsertAndEmpytyPreRemainedData();
            }
        }