]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
correct swapping
authorhades <hades>
Sat, 4 Sep 1999 15:39:25 +0000 (15:39 +0000)
committerhades <hades>
Sat, 4 Sep 1999 15:39:25 +0000 (15:39 +0000)
hadaq/showevt.c
hadaq/subevt.c

index c78236b93f7500669a6b775fd3ce2db51ddfea71..b04731e5798a66a0005e4ec65e6d710d24385689 100644 (file)
@@ -1,4 +1,4 @@
-static char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/showevt.c,v 6.1 1999-08-31 10:37:25 muench Exp $";
+static char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/showevt.c,v 6.2 1999-09-04 15:39:25 hades Exp $";
 
 #define _ANSI_C_SOURCE
 #include <stddef.h>
@@ -36,34 +36,25 @@ int analyseEvt(void *evt)
                printf("size: 0x%08x  decoding: 0x%08x  id: 0x%08x  trigNr: 0x%08x\n",
                           SubEvt_size(subEvt), SubEvt_decoding(subEvt), SubEvt_id(subEvt), SubEvt_trigNr(subEvt));
                if (SubEvt_decoding(subEvt) == SubEvtDecoding_32bitData) {
-                       UInt4 *data;
-
-                       data = SubEvt_data(subEvt);
                        for (i = 0; i < SubEvt_dataSize(subEvt) / sizeof(UInt4); i++) {
                                if (i % 4 == 0) {       /* newline and the offset in the subEvt */
-                                       printf("\n0x%08x:", (char *) data - (char *) SubEvt_data(subEvt));
+                                       printf("\n%08d:", i);
                                }
-                               printf("  0x%08x", data[i]);
+                               printf("  0x%08x", SubEvt_dataValue(subEvt, i));
                        }
                } else if (SubEvt_decoding(subEvt) == SubEvtDecoding_16bitData) {
-                       UInt2 *data;
-
-                       data = SubEvt_data(subEvt);
                        for (i = 0; i < SubEvt_dataSize(subEvt) / sizeof(UInt2); i++) {
                                if (i % 8 == 0) {       /* newline and the offset in the subEvt */
-                                       printf("\n0x%08x:", (char *) data - (char *) SubEvt_data(subEvt));
+                                       printf("\n%08d:", i);
                                }
-                               printf("  0x%04x", data[i]);
+                               printf("  0x%04x", SubEvt_dataValue(subEvt, i));
                        }
                } else if (SubEvt_decoding(subEvt) == SubEvtDecoding_8bitData) {
-                       UInt1 *data;
-
-                       data = SubEvt_data(subEvt);
                        for (i = 0; i < SubEvt_dataSize(subEvt) / sizeof(UInt1); i++) {
-                               if (i % 8 == 0) {       /* newline and the offset in the subEvt */
-                                       printf("\n0x%08x:", (char *) data - (char *) SubEvt_data(subEvt));
+                               if (i % 16 == 0) {      /* newline and the offset in the subEvt */
+                                       printf("\n%08d:", i);
                                }
-                               printf("  0x%02x", data[i]);
+                               printf("  0x%02x", SubEvt_dataValue(subEvt, i));
                        }
                } else if (SubEvt_decoding(subEvt) == SubEvtDecoding_text) {
                        char *data;
index 178026eb5d0e12e17f2ccafd5f465ff4b0954641..1d3c059e071dce0cb8df9dfaea406df978cfcd10 100644 (file)
@@ -1,4 +1,4 @@
-static char rcsId[] = "$Id: subevt.c,v 6.1 1999-08-31 10:37:25 muench Exp $";
+static char rcsId[] = "$Id: subevt.c,v 6.2 1999-09-04 15:39:25 hades Exp $";
 
 #include <stdlib.h>
 #include <errno.h>
@@ -36,6 +36,35 @@ void *SubEvt_data(const void *my)
        return (void *) ((char *) my + SubEvt_hdrSize());
 }
 
+UInt4 SubEvt_dataValue(const void *my, unsigned idx) {
+       UInt4 val;
+
+       switch (SubEvt_alignment(my)) {
+       case 4:
+               if (SubEvt_isSwapped(my)) {
+                       UInt4 v;
+                       swabInt4(((UInt4 *)SubEvt_data(my)) + idx, &v, 4);
+                       val = v;
+               } else {
+                       val = ((UInt4 *)SubEvt_data(my))[idx];
+               }
+               break;
+       case 2:
+               if (SubEvt_isSwapped(my)) {
+                       UInt2 v;
+                       swab(((UInt2 *)SubEvt_data(my)) + idx, &v, 2);
+                       val = v;
+               } else {
+                       val = ((UInt2 *)SubEvt_data(my))[idx];
+               }
+               break;
+       default:
+               val = ((UInt1 *)SubEvt_data(my))[idx];
+               break;
+       }
+       return val;
+}
+
 UInt4 SubEvt_id(const void *my)
 {
        return SubEvt_hdrValue(my, SubEvtIdx_id);