Пример #1
0
        private void ProcFrame(ByteRingBuffer ringBuffer, uint lenPlusOne)
        {
            switch (ringBuffer.Front)
            {
            case 0x10:
                break;

            case 0x14:
                int numFr;
                ringBuffer.Pop();
                numFr = ((int)lenPlusOne - 2) / 14;
                while (numFr > 0)
                {
                    --numFr;
                    _fr[0x0] = ringBuffer.Front; ringBuffer.Pop();
                    _fr[0x1] = ringBuffer.Front; ringBuffer.Pop();
                    _fr[0x2] = ringBuffer.Front; ringBuffer.Pop();
                    _fr[0x3] = ringBuffer.Front; ringBuffer.Pop();
                    _fr[0x4] = ringBuffer.Front; ringBuffer.Pop();
                    _fr[0x5] = ringBuffer.Front; ringBuffer.Pop();
                    _fr[0x6] = ringBuffer.Front; ringBuffer.Pop();
                    _fr[0x7] = ringBuffer.Front; ringBuffer.Pop();
                    _fr[0x8] = ringBuffer.Front; ringBuffer.Pop();
                    _fr[0x9] = ringBuffer.Front; ringBuffer.Pop();
                    _fr[0xa] = ringBuffer.Front; ringBuffer.Pop();
                    _fr[0xb] = ringBuffer.Front; ringBuffer.Pop();
                    _fr[0xc] = ringBuffer.Front; ringBuffer.Pop();
                    _fr[0xd] = ringBuffer.Front; ringBuffer.Pop();
                    HandleMsg();
                }
                ringBuffer.Pop();
                lenPlusOne = 0;
                break;

            case 0x17:
                break;

            default:
                break;
            }


            ringBuffer.Pop(lenPlusOne);
        }
Пример #2
0
        private void ProcessData(ByteRingBuffer ringBuffer)
        {
            /* tx tasks */
            if (_timeSched.Process())
            {
                /* every 10 ms */
                _serialClient.Write(_pollMsg);
                _serialClient.Write(_chirpReq);
            }
            /* rx process */
            bool stay = true;

            while (stay)
            {
                switch (_state)
                {
                case 0:
                    if (ringBuffer.Count < 1)
                    {
                        stay = false;     /* not enough data */
                    }
                    else
                    {
                        /* we have data */
                        if (ringBuffer.Front == 0x5a)
                        {
                            ++_state;
                        }
                        /* pop it */
                        ringBuffer.Pop();
                    }
                    break;

                case 1:
                    if (ringBuffer.Count < 2)
                    {
                        stay = false;     /* not enough data */
                    }
                    else
                    {
                        byte h = ringBuffer.Front;
                        ringBuffer.Pop();
                        byte l = ringBuffer.Front;
                        ringBuffer.Pop();

                        _len   = h;
                        _len <<= 8;
                        _len   = l;
                        ++_state;
                    }
                    break;

                case 2:
                    if (ringBuffer.Count < (_len + 1))
                    {
                        stay = false;     /* not enough data */
                    }
                    else
                    {
                        ProcFrame(ringBuffer, _len + 1);
                        _state = 0;
                    }
                    break;
                }
            }
        }