From 569820ec9f62503ea927ee46f031907a156e521b Mon Sep 17 00:00:00 2001 From: hades Date: Sat, 4 Sep 1999 15:39:25 +0000 Subject: [PATCH] correct swapping --- hadaq/showevt.c | 25 ++++++++----------------- hadaq/subevt.c | 31 ++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/hadaq/showevt.c b/hadaq/showevt.c index c78236b..b04731e 100644 --- a/hadaq/showevt.c +++ b/hadaq/showevt.c @@ -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 @@ -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; diff --git a/hadaq/subevt.c b/hadaq/subevt.c index 178026e..1d3c059 100644 --- a/hadaq/subevt.c +++ b/hadaq/subevt.c @@ -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 #include @@ -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); -- 2.43.0