Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 /* 
0002 ** formatIO.C
0003 ** 
0004 ** Author: $Author: phnxbld $  
0005 **   Date: $Date: 2009/08/19 12:31:53 $ 
0006 ** 
0007 ** $Log: formatIO.C,v $
0008 ** Revision 1.4  2009/08/19 12:31:53  phnxbld
0009 ** fix compiler warning
0010 **
0011 ** Revision 1.3  2005/12/19 16:29:24  pinkenbu
0012 ** fix insure bad format warnings
0013 **
0014 ** Revision 1.2  2002/05/31 22:15:42  purschke
0015 ** mlp -- went through the insure report and tried to fix
0016 ** every little problem there is, unused variables, dead statements,
0017 ** all. It'll probably take another round to complete, but it should get
0018 ** rid of most warnings.
0019 **
0020 ** Revision 1.1.1.1  2000/07/21 01:51:13  purschke
0021 ** mlp -- adding the new automakified "basic" module to CVS.
0022 **
0023 **
0024 ** Revision 1.4  1998/12/11 22:02:03  markacs
0025 ** (stephen markacs) adding log into cvs tags
0026 ** 
0027 */
0028 /*
0029 **   formatIO.C
0030 **
0031 **
0032 **   Routines to dump frames and packets
0033 **
0034 */
0035 
0036 #include <stdio.h>
0037 #include "phenixOnline.h"
0038 #include "Cframe.h"
0039 #include "framePublic.h"
0040 #include "packetPublic.h"
0041 #include "Cpacket.h"
0042 #include "dataBlock.h"
0043 #include "formatIO.h"
0044 
0045 /*
0046 **  dumpFrame 
0047 */
0048 
0049 VALUE_ret dumpFrame (FRAME_ptr frame_ptr)
0050 {
0051   PHDWORD *dump_ptr;
0052   UINT  nDwords;
0053   VALUE_ret result;
0054 
0055   /*
0056   ** Dump the header
0057   */
0058   result = dumpFrameHdr (frame_ptr);
0059   if (result == valueFailure)
0060     {
0061       printf ("Unknown or invalid Frame header \n");
0062       return valueFailure;
0063     }
0064 
0065   /*
0066   **  Get number of Dwords in frame contents
0067   */
0068   nDwords = getFrameDataLength (frame_ptr);
0069   dump_ptr = findFrameDataStart (frame_ptr);    
0070 
0071   /*
0072   **  For now just dump data + history in Hex format
0073   */
0074   printf ("Dump of frame data: \n");
0075 
0076   {
0077     /*
0078     ** Loop through entire frame dumping each word
0079     */
0080     UINT iDword;
0081 
0082     for (iDword = 0; iDword < nDwords; iDword++)
0083       printf ("Frame Word %u = %#8x \n", iDword, *dump_ptr++);
0084   }
0085 
0086   return 0;
0087 }
0088 
0089 VALUE_ret dumpFramePackets (FRAME_ptr frame_ptr)
0090 {
0091   PHDWORD *dump_ptr;
0092   VALUE_ret result;
0093 
0094   /*
0095   ** Dump the frame header
0096   */
0097   result = dumpFrameHdr (frame_ptr);
0098   if (result == valueFailure) 
0099     {
0100       printf ("Unknown or invalid Frame header \n");
0101       return valueFailure;
0102     }
0103 
0104 
0105   /*
0106   **  Now loop through the frame dumping the packets
0107   */
0108   dump_ptr = findFirstFramePacket(frame_ptr);
0109   while (dump_ptr != ptrFailure)
0110     {
0111       VALUE_ret result;
0112 
0113       /*
0114       **  Dump the packet.
0115       */
0116       result = dumpPacket((PACKET_ptr) dump_ptr);
0117       if (result == valueFailure)
0118     {
0119       printf ("Error in frame data -- unknown or invalid packet \n");
0120       return valueFailure;
0121     }
0122 
0123       dump_ptr = findNextFramePacket(frame_ptr, dump_ptr);
0124     }
0125 
0126   return 0;
0127 }
0128 
0129 
0130 VALUE_ret dumpFrameHdr (FRAME_ptr frame_ptr)
0131 {
0132   /*
0133   **  Check for valid frame header and correct version
0134   */
0135   if (!validFrameHdr (frame_ptr))
0136     {
0137       /*
0138       **  We have received an "invalid" frame, report error
0139       */
0140       return valueFailure;
0141     }
0142 
0143   /*
0144   ** Now that we are satisfied that we have a valid header
0145   **     define a proper pointer to the current header type
0146   */
0147 
0148   printf ("Frame Mark = %#.8x \n", getFrameMark(frame_ptr));
0149 
0150   printf ("Frame version = %u, Frame Hdr length = %u \n", 
0151       getFrameHdrVersion(frame_ptr), getFrameHdrLength(frame_ptr));
0152 
0153 
0154   printf ("data type = %u, Frame type = %u, Source Id = %u \n", 
0155       getFrameDataType(frame_ptr), getFrameType(frame_ptr), 
0156       getFrameSourceId(frame_ptr));
0157 
0158   printf ("Frame length = %u, Error Length = %u, History Length = %u \n", 
0159       getFrameLength(frame_ptr), getFrameErrorLength(frame_ptr), 
0160       getFrameHistoryLength(frame_ptr));
0161 
0162   printf ("Frame status = %#.4x, Frame padding = %u, Align length = %u \n", 
0163       getFrameStatus(frame_ptr), getFramePadding(frame_ptr), 
0164       getFrameAlignLength(frame_ptr));
0165   {
0166     UINT iAlign;
0167     /*
0168     ** Dump the alignment block
0169     */
0170 
0171     PHDWORD* align_ptr = findFrameAlignBlock(frame_ptr);
0172 
0173     for (iAlign = 0; iAlign < getFrameAlignLength(frame_ptr); iAlign++)
0174       printf ("Alignment block word %u = %#.8x \n", iAlign, *align_ptr++);
0175   }
0176 
0177   return 0;
0178 }
0179 
0180 /*
0181 **  Routine to dump the header and contents of a packet
0182 */
0183 VALUE_ret dumpPacket (PACKET_ptr packet_ptr)
0184 {
0185   /*
0186   **  Check for valid packet header and correct version
0187   */  
0188   if (!validPacketHdr (packet_ptr)) {
0189     /*
0190     **  We have received an "invalid" packet, report error
0191     */
0192     return valueFailure;
0193   }
0194   
0195   /*
0196   ** Dump the header
0197   */
0198   printf ("Packet Length: %u", getPacketLength(packet_ptr));
0199 
0200   printf ("Packet HDR version: %u, Packet HDR length:%u",
0201       getPacketHdrVersion(packet_ptr), getPacketHdrLength(packet_ptr));
0202 
0203   printf ("Packet Status bits: %#.4x \n", getPacketStatus(packet_ptr));
0204 
0205   printf ("Packet Ident: %u", getPacketId(packet_ptr));
0206 
0207   printf ("Endianism: %u, Padding: %u \n", getPacketEndianism(packet_ptr), 
0208       getPacketPadding(packet_ptr));
0209   
0210   printf ("Error Length: %u, Debug Length: %u \n", 
0211       getPacketErrorLength(packet_ptr), getPacketDebugLength(packet_ptr));
0212   
0213   /*
0214   ** Print-out structure-specific information
0215   */
0216   switch (getPacketStructure(packet_ptr)) {
0217   case Unstructured: 
0218     {
0219       UINT wordSize = getUnstructPacketWordSize(packet_ptr);
0220       PHDWORD numWords = getUnstructPacketDataLengthWords(packet_ptr);
0221 
0222       printf ("Unstructured packet, Format: %u, Word Size: %u, Length (words): %u",
0223           getUnstructPacketHitFormat(packet_ptr), wordSize, numWords);
0224           
0225       /*
0226       **  Now dump the contents of the packet
0227       */
0228       {
0229         UINT iWord;
0230     PHDWORD dataWord = 0; // init not needed but it suppresses compiler warning
0231         BYTE *dump_ptr;
0232 
0233     printf ("Dump of packet data: \n");
0234     /*
0235     **  Do a word-by-word dump of the packet
0236     */
0237     
0238     dump_ptr = (BYTE*) findPacketDataStart(packet_ptr);
0239     
0240     for (iWord = 0; iWord < numWords; iWord++) {
0241       switch(wordSize) 
0242         {
0243         case 1: { dataWord = *dump_ptr; break; }
0244         case 2: {dataWord = *((SWORD*) dump_ptr); break;}
0245         case 4: {dataWord = *((PHDWORD*) dump_ptr); break;}
0246         default: break; 
0247         }
0248       printf ("Packet Word %u = %#8x \n", iWord, dataWord);
0249       dump_ptr+=wordSize;
0250     }
0251       }
0252     }
0253   }
0254 
0255   /*
0256   ** Return success
0257   */
0258   return 0;
0259 }
0260 
0261