00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #ifndef OPAL_H224_Q922_H
00027 #define OPAL_H224_Q922_H
00028 
00029 #ifdef P_USE_PRAGMA
00030 #pragma interface
00031 #endif
00032 
00033 #ifndef _PTLIB_H
00034 #include <ptlib.h>
00035 #endif
00036 
00037 #include <opal/buildopts.h>
00038 
00039 #define Q922_HEADER_SIZE 3
00040 
00041 class Q922_Frame : public PBYTEArray
00042 {
00043   PCLASSINFO(Q922_Frame, PBYTEArray);
00044         
00045 public:
00046         
00047   Q922_Frame(PINDEX informationFieldSize = 260);
00048   ~Q922_Frame();
00049         
00050   BYTE GetHighOrderAddressOctet() const { return theArray[0]; }
00051   BYTE GetLowOrderAddressOctet() const { return theArray[1]; }
00052   void SetHighOrderAddressOctet(BYTE octet) { theArray[0] = octet; }
00053   void SetLowOrderAddressOctet(BYTE octet) { theArray[1] = octet; }
00054         
00055   BYTE GetControlFieldOctet() const { return theArray[2]; }
00056   void SetControlFieldOctet(BYTE octet) { theArray[2] = octet; }
00057         
00058   BYTE *GetInformationFieldPtr() const { return (BYTE *)(theArray + Q922_HEADER_SIZE); }
00059         
00060   PINDEX GetInformationFieldSize() const { return informationFieldSize; }
00061   void SetInformationFieldSize(PINDEX size);
00062   
00066   PBoolean DecodeAnnexQ(const BYTE *buffer, PINDEX size);
00067   
00070   PINDEX GetAnnexQEncodedSize() const;
00071   
00075   PBoolean EncodeAnnexQ(BYTE *buffer, PINDEX & size) const;
00076   
00080   PBoolean DecodeHDLC(const BYTE *data, PINDEX size);
00081         
00085   PINDEX GetHDLCEncodedSize() const;
00086   
00090   PBoolean EncodeHDLC(BYTE *buffer, PINDEX & size) const;
00091 
00099   PBoolean EncodeHDLC(BYTE *buffer, PINDEX & size, BYTE & bitPosition) const;
00100         
00101 protected:
00102         
00103   PINDEX informationFieldSize;
00104         
00105 private:
00106 
00107   
00108   inline PBoolean FindFlagEnd(const BYTE *buffer, PINDEX bufferSize, PINDEX & octetIndex, BYTE & bitIndex);
00109   inline BYTE DecodeOctet(const BYTE *buffer, BYTE *destination, PINDEX & octetIndex, BYTE & bitIndex, BYTE & onesCounter);
00110   inline BYTE DecodeBit(const BYTE *buffer, PINDEX & octetIndex, BYTE & bitIndex);
00111         
00112   inline void EncodeOctet(BYTE octet, BYTE *buffer, PINDEX & octetIndex, BYTE & bitIndex, BYTE & onesCounter) const;
00113   inline void EncodeOctetNoEscape(BYTE octet, BYTE *buffer, PINDEX & octetIndex, BYTE & bitIndex) const;
00114   inline void EncodeBit(BYTE bit, BYTE *buffer, PINDEX & octetIndex, BYTE & bitIndex) const;
00115         
00116   inline WORD CalculateFCS(const BYTE*data, PINDEX length) const;
00117 };
00118 
00119 #endif // OPAL_H224_Q922_H
00120