00001
00002 #include "l3BankUtils.h"
00003 #include "l3Swap.h"
00004
00005 #include <stdlib.h>
00006 #include <string.h>
00007
00008 void *offlen2ptr(void *base, struct offlen ol)
00009 {
00010 int off, len;
00011
00012 if( ((bankHeader*)base)->byte_order == DAQ_RAW_FORMAT_ORDER) {
00013 off=ol.off;
00014 len=ol.len;
00015 } else {
00016 off=swap32(ol.off);
00017 len=swap32(ol.len);
00018 }
00019
00020 void *ptr;
00021 if (len > 0)
00022 ptr = (void *)((char *)base + off*4);
00023 else
00024 ptr = (void *)0;
00025
00026 return ptr;
00027 }
00028
00029
00030
00031 void *offlen2ptr(void *base, struct offlen ol, char *type)
00032 {
00033
00034 void *ptr = offlen2ptr(base, ol);
00035
00036 return validate(ptr, type);
00037 }
00038
00039
00040
00041 void *validate(void * ptr, char *type)
00042 {
00043 if(validateBank(ptr, type))
00044 return ptr;
00045 else
00046 return NULL;
00047 };
00048
00049
00050 bool validateBank(void * ptr, char *type)
00051 {
00052 struct bankHeader *bh =(struct bankHeader *) ptr;
00053 int typelen;
00054 for(typelen = 1; typelen<8 && type[typelen-1]!=' ';typelen++);
00055
00056
00057 if(ptr == NULL)
00058 return false;
00059
00060 else if (strncmp(type, bh->bank_type, typelen))
00061 {
00062
00063
00064
00065 return false;
00066 }
00067 else
00068 return true;
00069 }
00070
00071 int bankSize(bankHeader bh)
00072 {
00073 if (bh.byte_order == DAQ_RAW_FORMAT_ORDER) {
00074 return (bh.length * 4);
00075 } else {
00076 return (swap32(bh.length) * 4);
00077 }
00078
00079 }