# SFBFrame.h

Go to the documentation of this file.

    00001 /*                                             -*- mode:C++; fill-column:100 -*-
    00002   SFBFrame.h - Packet de/framing methods
    00003   Copyright (C) 2009 The Regents of the University of New Mexico.  All rights reserved.
    00004
    00005   This library is free software; you can redistribute it and/or
    00006   modify it under the terms of the GNU Lesser General Public
    00007   License as published by the Free Software Foundation; either
    00008   version 2.1 of the License, or (at your option) any later version.
    00009
    00010   This library is distributed in the hope that it will be useful,
    00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013   Lesser General Public License for more details.
    00014
    00015   You should have received a copy of the GNU General Public License
    00016   along with this library; if not, write to the Free Software
    00017   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00018   USA
    00019 */
    00020
    00027 #ifndef SFBFRAME_H_
    00028 #define SFBFRAME_H_
    00029
    00030 #include "SFBTypes.h"
    00031 #include "SFBByteBuffer.h"
    00032 #include "SFBAssert.h"
    00033 #include "SFBPacket.h"
    00034
    00038 class SFBFrame {
    00039 public:
    00040   SFBFrame(SFBRxByteBuffer & r, SFBTxByteBuffer & t, PacketBuffer & p, u8 face) ;
    00041
    00042   u8 * pollForRxPacket() ;
    00043
    00044   bool txCanAddByte() ;
    00045   void txDataByte(u8 data) ;
    00046   void txEndPacket();
    00047
    00048   void reset() ;
    00049   void resetRx() ;
    00050
    00051   void resetTx() ;
    00052
    00053
    00054   enum FrameTypes {
    00055     STANDARD_PACKET,
    00056     BYTE_PER_PACKET,
    00057     MAX_FRAME_TYPES
    00058   };
    00059
    00060   void setRxFrameType(u32 frameType) ;
    00061   void setTxFrameType(u32 frameType) ;
    00062   u32 getRxFrameType() { return rxFrameType; }
    00063   u32 getTxFrameType() { return txFrameType; }
    00064 private:
    00065
    00066   bool rxByte(int byteOrErrorVal);
    00067   bool rxByteNonstandard(int byteVal);
    00068
    00069   bool rxStoreRaw(u8 byte);
    00070   void rxSetupError(u8 flags) ;
    00071   void rxSetupPacket() ;
    00072
    00073   void txDataByteNonstandard(u8 data);
    00074
    00075   SFBRxByteBuffer & rxBuf;
    00076   SFBTxByteBuffer & txBuf;
    00077   PacketBuffer & deframeBuffer;
    00078   int txCount;
    00079   int rxCount;                  // ==-1 if lost sync due to error or frame overflow
    00080   bool rxEscape;                // true if halfway through escape sequence
    00081   u8 rxFrameType;
    00082   u8 txFrameType;
    00083   const u8 face;
    00084 };
    00085 #endif /* SFBFRAME_H_ */