Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:44

0001 /* 
0002 ** Cpacket.h
0003 ** 
0004 ** Author: $Author: purschke $  
0005 **   Date: $Date: 2000/07/21 01:51:10 $ 
0006 ** 
0007 ** $Log: Cpacket.h,v $
0008 ** Revision 1.1.1.1  2000/07/21 01:51:10  purschke
0009 ** mlp -- adding the new automakified "basic" module to CVS.
0010 **
0011 **
0012 ** Revision 1.6  1998/12/17 21:57:06  phoncs
0013 ** (stephen markacs) better bounds checking in version gets
0014 **
0015 ** Revision 1.5  1998/12/11 22:01:13  markacs
0016 ** (stephen markacs) adding log into cvs tags
0017 ** 
0018 */
0019 /*
0020 **  Cpacket.h
0021 **
0022 **    Defines prototypes for all public functions in Cpacket.C.
0023 **
0024 **    These routines provide access to information in the header, allow 
0025 **    modification of data in the header and provide various logical
0026 **    tests of packet integrity, etc.  The version independent
0027 **    routines contained here are inlined.  Version independent 
0028 **    routines which are not inlined are defined in Cpacket.C.
0029 **
0030 **    In addition to the packet header, there is a small data
0031 **    descriptor of one or two dwords which immediately follows the
0032 **    packet header at the head of the data block. The data descriptor
0033 **    contains information specific to the data block and has a format which  
0034 **    varies depending on the type of data structure used in the data
0035 **    block. The descriptor is defined in dataBlock.h and is placed
0036 **    after the packet in packetRoutines.C. 
0037 **
0038 */
0039 #ifndef _CPACKET_
0040 #define _CPACKET_
0041 
0042 #ifdef __cplusplus
0043 extern "C" {
0044 #endif
0045 
0046 #include "phenixOnline.h"
0047 #include "packetPublic.h"
0048 #include "packetHdr.h"
0049 #include "formatError.h"
0050 
0051   /*
0052   **  The following routines are GENERIC and do not depend on packet 
0053   **  header version. They are either inlined in this file or coded in 
0054   **  Cpacket.C
0055   */  
0056 
0057 INLINE_P LOGIC_ret currentPacket (PACKET_ptr);
0058 
0059 INLINE_P VALUE_ret getPacketLength (PACKET_ptr);
0060 INLINE_P VALUE_ret getPacketHdrLength (PACKET_ptr);
0061 INLINE_P VALUE_ret getPacketHdrVersion (PACKET_ptr);
0062 
0063 INLINE_P LOGIC_ret setPacketHdrVersion(PACKET_ptr, UINT);
0064 INLINE_P LOGIC_ret setPacketHdrLength(PACKET_ptr, UINT);
0065 INLINE_P LOGIC_ret setPacketLength(PACKET_ptr, PHDWORD);
0066 
0067 PTR_ret findPacketEnd (PACKET_ptr);
0068 PTR_ret findPacketDataStart (PACKET_ptr);
0069 
0070 VALUE_ret extendPacketDataBlock(const PACKET_ptr, UINT, int);
0071 VALUE_ret extendPacketDebugBlock(const PACKET_ptr, UINT, int);
0072 VALUE_ret extendPacketErrorBlock(const PACKET_ptr, UINT, int);
0073 VALUE_ret extendPacketLength(const PACKET_ptr, UINT, int);
0074 
0075 LOGIC_ret removePacketPadding(PACKET_ptr);
0076 
0077 INLINE_P void endianSwapError (PACKETERROR* outError, PACKETERROR* inError);
0078 
0079   /*
0080   **  The following routines execute functions that will depend on the
0081   **  version of the packet header. Outside the DCM's these routines
0082   **  use pointer tables defined below to execute a version-specific
0083   **  function with identical definition. For use in the DCM's the
0084   **  generic function names are #defined to be the version-specific 
0085   **  for the "current" packet header version being created in the DAQ.
0086   */
0087 
0088 #ifdef DCM 
0089 
0090 #define makePacketHdr makePacketHdrV1
0091 
0092 #define getPacketDebugLength getPacketV1DebugLength
0093 #define getPacketErrorLength getPacketV1ErrorLength
0094 #define getPacketNumErrors getPacketV1NumErrors
0095 #define getPacketEndianism getPacketV1Endianism
0096 #define getPacketId getPacketV1Id
0097 #define getPacketPadding getPacketV1Padding
0098 #define getPacketStructure getPacketV1Structure
0099 #define getPacketStatus getPacketV1Status
0100 #define getPacketDataDescrLength getPacketDataDescrLengthV1
0101 
0102 #define setPacketDebugLength setPacketV1DebugLength
0103 #define setPacketNumErrors setPacketV1NumErrors
0104 #define setPacketEndianism setPacketV1Endianism
0105 #define setPacketId setPacketV1Id
0106 #define setPacketPadding setPacketV1Padding
0107 #define setPacketStructure  setPacketV1Structure
0108 #define setPacketStatus setPacketV1Status
0109 #define setPacketErrorLength setPacketV1ErrorLength
0110 
0111 #define orPacketStatus orPacketV1Status
0112 #define adjustPacketDataLength adjustPacketV1DataLength
0113 #define adjustPacketDebugLength adjustPacketV1DebugLength
0114 #define adjustPacketErrorLength adjustPacketV1ErrorLength
0115 
0116 #define findPacketErrorStart findPacketV1ErrorStart
0117 #define findPacketDebugStart findPacketV1DebugStart
0118 #define findPacketDataStart findPacketV1DataStart
0119 #define findPacketDataEnd findPacketV1DataEnd
0120 
0121 #define validPacketHdr validPacketV1Hdr
0122 #define emptyPacket emptyPacketV1   
0123 
0124 #else
0125 
0126 VALUE_ret makePacketHdr(const PACKET_ptr, UINT);
0127 VALUE_ret getPacketDataLength (const PACKET_ptr);
0128 VALUE_ret getPacketDebugLength (const PACKET_ptr);
0129 VALUE_ret getPacketErrorLength (const PACKET_ptr);
0130 VALUE_ret getPacketNumErrors (const PACKET_ptr);
0131 VALUE_ret getPacketPadding (const PACKET_ptr);
0132 VALUE_ret getPacketId (const PACKET_ptr);
0133 VALUE_ret getPacketStatus (PACKET_ptr);
0134 VALUE_ret getPacketStructure (const PACKET_ptr);
0135 VALUE_ret getPacketEndianism (const PACKET_ptr);
0136 VALUE_ret getPacketDataDescrLength (const PACKET_ptr);
0137 
0138 LOGIC_ret setPacketDebugLength (PACKET_ptr, UINT); 
0139 LOGIC_ret setPacketNumErrors (PACKET_ptr, UINT);
0140 LOGIC_ret setPacketEndianism (PACKET_ptr, UINT);
0141 LOGIC_ret setPacketId (PACKET_ptr, UINT);
0142 LOGIC_ret setPacketPadding (PACKET_ptr, UINT);
0143 LOGIC_ret setPacketStructure (PACKET_ptr, UINT); 
0144 LOGIC_ret setPacketStatus (PACKET_ptr, UINT);
0145 LOGIC_ret setPacketErrorLength  (PACKET_ptr, UINT);
0146 LOGIC_ret setPacketDataDescrLength (PACKET_ptr, UINT);
0147 
0148 VALUE_ret orPacketStatus (PACKET_ptr, UINT);   
0149 LOGIC_ret validPacketHdr (PACKET_ptr);
0150 LOGIC_ret emptyPacket (PACKET_ptr);
0151 
0152 PTR_ret findPacketDataDescr(PACKET_ptr);
0153 PTR_ret findPacketDataStart(PACKET_ptr);
0154 PTR_ret findPacketDataEnd (PACKET_ptr);
0155 PTR_ret findPacketDebugStart (PACKET_ptr);
0156 PTR_ret findPacketErrorStart (PACKET_ptr);
0157 
0158 VALUE_ret adjustPacketDataLength (PACKET_ptr, int);
0159 VALUE_ret adjustPacketErrorLength (PACKET_ptr, int);
0160 VALUE_ret adjustPacketDebugLength (PACKET_ptr, int);
0161 
0162 #endif
0163 
0164 
0165 /* 
0166 **  ==================================================================
0167 **  Inlined GENERIC routines that do not need the indirection arrays
0168 **  ==================================================================
0169 */
0170 
0171 INLINE_D VALUE_ret getPacketHdrLength (PACKET_ptr packet_ptr)
0172 {
0173   return getBitsMACRO(packet_ptr, 
0174               PACKET_HDR_LENGTH_OFFSET_OF_DWORD,
0175               PACKET_HDR_LENGTH_OFFSET_IN_DWORD,
0176               PACKET_HDR_LENGTH_MASK);
0177 }
0178 
0179 
0180 INLINE_D VALUE_ret getPacketLength (PACKET_ptr packet_ptr)
0181 {
0182   PHDWORD length = getWordMACRO(packet_ptr, PACKET_LENGTH_OFFSET_OF_DWORD);
0183 
0184 #ifdef STRONGCHECK
0185   if ((length&(1<<32))!=0) return valueFailure;
0186 #endif
0187 
0188   return length;
0189 }
0190 
0191 INLINE_D VALUE_ret getPacketHdrVersion (PACKET_ptr packet_ptr)
0192 {
0193  BYTE hdrVersion = (BYTE)getBitsMACRO(packet_ptr, 
0194                       PACKET_HDR_VERSION_OFFSET_OF_DWORD,
0195                       PACKET_HDR_VERSION_OFFSET_IN_DWORD,
0196                       PACKET_HDR_VERSION_MASK);
0197 
0198   if ((hdrVersion >= numPacketVersions)||(hdrVersion==0)) {
0199     setPacketError(FORMAT_ERR_INVALID_PACKET_HDRVERSION, 
0200            packet_ptr, hdrVersion);
0201     return valueFailure;
0202   }  
0203 
0204   return hdrVersion;
0205 }
0206 
0207 INLINE_D LOGIC_ret setPacketHdrVersion (PACKET_ptr packet_ptr, UINT hdrVersion)
0208 {
0209 #ifdef CHECK
0210   if ((hdrVersion >= numPacketVersions)||(hdrVersion==0)) {
0211     setPacketError(FORMAT_ERR_INVALID_PACKET_HDRVERSION, 
0212            packet_ptr, hdrVersion);
0213     return valueFailure;
0214   }  
0215 #endif 
0216   setBitsMACRO(packet_ptr, 
0217            PACKET_HDR_VERSION_OFFSET_OF_DWORD,
0218            PACKET_HDR_VERSION_OFFSET_IN_DWORD, 
0219            PACKET_HDR_VERSION_MASK, hdrVersion);
0220   return TRUE;
0221 }
0222 
0223 INLINE_D LOGIC_ret setPacketLength (PACKET_ptr packet_ptr, PHDWORD length)
0224 {
0225   /*
0226   **  Currently we do no checking -- return "true"
0227   */
0228 #ifdef CHECK
0229   if (length >= MAX_DWORD_VALUE) {
0230     setPacketError(FORMAT_ERR_LENGTH_OVERFLOW, packet_ptr, length);
0231     return FALSE;
0232   }
0233 #endif
0234   setWordMACRO(packet_ptr, PACKET_LENGTH_OFFSET_OF_DWORD, length);
0235   return TRUE;
0236 }
0237 
0238 
0239 INLINE_D LOGIC_ret setPacketHdrLength (PACKET_ptr packet_ptr, UINT hdrLength)
0240 {
0241 #ifdef CHECK
0242   if (hdrLength >= ) {
0243     setPacketError(FORMAT_ERR_INVALID_HDRLENGTH, packet_ptr, hdrLength);
0244     return FALSE;
0245   }
0246 #endif
0247 
0248   setBitsMACRO(packet_ptr, PACKET_HDR_LENGTH_OFFSET_OF_DWORD,
0249            PACKET_HDR_LENGTH_OFFSET_IN_DWORD, 
0250            PACKET_HDR_LENGTH_MASK, hdrLength);
0251   return TRUE;
0252 }
0253 
0254 
0255 INLINE_D LOGIC_ret currentPacket (PACKET_ptr packet_ptr)
0256 {
0257   UINT version = getPacketHdrVersion(packet_ptr);
0258   return (version == currentPacketHdrVersion);
0259 }
0260 
0261 INLINE_D void endianSwapError (PACKETERROR* outError, PACKETERROR* inError)
0262 {
0263   /*
0264   **  Execute the swap function provided in the V1 error routines
0265   */
0266   endianSwapErrorV1 (outError, inError);
0267 }
0268 
0269 #ifdef __cplusplus
0270 }
0271 #endif 
0272 /* end of extern "C" */
0273 
0274 #endif
0275 /* end of ifndef _CPACKET_ */
0276 
0277 
0278 
0279 
0280 
0281 
0282 
0283 
0284 
0285