diff --git a/examples/ChangeLog b/examples/ChangeLog new file mode 100644 index 0000000000000000000000000000000000000000..bbd73d90cdb319ae732f97ef5d7ca1f9fb4e0d1c --- /dev/null +++ b/examples/ChangeLog @@ -0,0 +1,22 @@ +5 April 2005 +TAG CVS: PACKETLIB_1_3_4 ++ added the possibility to have an even number of byte in the definition of a block ++ addedd the Packet::printPacketOutputStream() ++ correction of the [SourceDataFieldBlock] not found keyword into the SDFBlockFixed ++ correction of the calculation of the dimension with tail + +22 March 2005 +TAG CVS: PACKETLIB_1_3_4_BETA2 +PacketLib 1.3.4 beta 2 ++ correct the bug for the setFieldValue4_13 and 3_13 ++ added the exception generation when for the 24 bit field value there are an out of range: +#define U24BITINTGEGERUNSIGNED_MAX 16777215 +#define U24BITINTGEGERSIGNED_MIN -8388607 +#define U24BITINTGEGERSIGNED_MAX 8388607 + +9 March 2005 (1.3.4 beta) ++ modified the management of the fields (class PartOfPacket). Now a field should be divided between two words + +2 March 2005 (1.3.3) ++ bug of the InputFile::isEOF() ++ added PTC/PFC 4/13 3/14 3/13 diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..707c75a6e8fb40acf3da1cd77ec5baf2808ac3ea --- /dev/null +++ b/examples/Makefile @@ -0,0 +1,160 @@ +############################################################################# +# Makefile for install: PacketLib +# Project: PacketLib +# Use make variable_name=' options ' to override the variables or make -e to +# override the file variables with the environment variables +# make CFLAGS='-g' or make prefix='/usr' +############################################################################# + +SHELL = /bin/sh + +####### 1) Project names and system + +#SYSTEM: linux or QNX +SYSTEM = linux +PROJECT=PacketLib + +####### 2) Directories for the installation + +# Prefix for each installed program. Only ABSOLUTE PATH +prefix=/usr/local +exec_prefix=$(prefix) +# The directory to install the binary files in. +bindir=$(exec_prefix)/bin +# The directory to install the local configuration file. +datadir=$(exec_prefix)/share +# The directory to install the libraries in. +libdir=$(exec_prefix)/lib +# The directory to install the info files in. +infodir=$(exec_prefix)/info +# The directory to install the include files in. +includedir=$(exec_prefix)/include + +####### 3) Directories for the compiler + +OBJECTS_DIR = obj +SOURCE_DIR = examples +LIB_DESTDIR = lib +INCLUDE_DIR = include +LIB_NAME = libpacket +VER_FILE_NAME = PlVersion.h + +####### 4) Compiler, tools and options + +CC = gcc +CXX = g++ +#Insert the optional parameter to the compiler. The CFLAGS could be changed externally by the user +#- g3 +CFLAGS = -O2 -O0 +#-O2 -O0 -g3 +#Set INCPATH to add the inclusion paths +INCPATH = -I $(includedir) +#Insert the implicit parameter to the compiler: +ALL_CFLAGS = -fexceptions -Wall $(INCPATH) $(CFLAGS) +ifeq ($(SYSTEM), QNX) + ALL_CFLAGS += -Vgcc_ntox86_gpp -lang-c++ +endif +#Use CPPFLAGS for the preprocessor +CPPFLAGS = +#Set LIBS for addition library +LIBS = -lstdc++ -lpacket +ifeq ($(SYSTEM), QNX) + LIBS += -lsocket +endif +LINK = g++ +#for link +LFLAGS = -shared -Wl,-soname,$(TARGET1) -Wl,-rpath,$(DESTDIR) +AR = ar cqs +TAR = tar -cf +GZIP = gzip -9f +COPY = cp -f +COPY_FILE= $(COPY) -p +COPY_DIR = $(COPY) -pR +DEL_FILE = rm -f +SYMLINK = ln -sf +DEL_DIR = rm -rf +MOVE = mv -f +CHK_DIR_EXISTS= test -d +MKDIR = mkdir -p + +####### 5) VPATH + +VPATH=$(SOURCE_DIR):$(INCLUDE_DIR): +vpath %.o $(OBJECTS_DIR) + +####### 6) Files of the project + +INCLUDE=$(foreach dir,$(INCLUDE_DIR), $(wildcard $(dir)/*.h)) +OBJECTS = in.o msgqclient.o msgqserver.o out.o + +####### 7) Only for library generation + +TARGET = $(LIB_NAME).so.$(shell cat version) +TARGETA = $(LIB_NAME).a +TARGETD = $(LIB_NAME).so.$(shell cat version) +TARGET0 = $(LIB_NAME).so +TARGET1 = $(LIB_NAME).so.$(shell cut version -f 1 -d '.') +TARGET2 = $(LIB_NAME).so.$(shell cut version -f 1 -d '.').$(shell cut version -f 2 -d '.') + +####### 8) Preliminar operations + +$(shell cut $(INCLUDE_DIR)/$(VER_FILE_NAME) -f 3 > version) +#WARNING: use -d ' ' if in the version.h the separator is a space + +####### 9) Pattern rules + +%.o : %.cpp + $(CC) $(CPPFLAGS) $(ALL_CFLAGS) -c $< -o $(OBJECTS_DIR)/$@ + +####### 10) Build rules + +all: makeobjdir $(OBJECTS) + $(CC) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/in $(OBJECTS_DIR)/in.o $(LIBS) + $(CC) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/out $(OBJECTS_DIR)/out.o $(LIBS) + $(CC) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/msgqclient $(OBJECTS_DIR)/msgqclient.o $(LIBS) + $(CC) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/msgqserver $(OBJECTS_DIR)/msgqserver.o $(LIBS) + +makeobjdir: + test -d $(OBJECTS_DIR) || mkdir -p $(OBJECTS_DIR) + +#clean: delete all files from the current directory that are normally created by building the program. +clean: + $(DEL_FILE) $(OBJECTS_DIR)/*.o + $(DEL_FILE) *~ core *.core + $(DEL_FILE) version + $(DEL_FILE) prefix + $(DEL_FILE) $(SOURCE_DIR)/msgqserver + $(DEL_FILE) $(SOURCE_DIR)/msgqclient + $(DEL_FILE) $(SOURCE_DIR)/in + $(DEL_FILE) $(SOURCE_DIR)/out + test $(OBJECTS_DIR) = . || $(DEL_DIR) $(OBJECTS_DIR) + + +#Delete all files from the current directory that are created by configuring or building the program. +distclean: clean + +#install: compile the program and copy the executables, libraries, +#and so on to the file names where they should reside for actual use. +install: + $(shell echo $(prefix) > prefix) + + # For library installation + $(COPY_FILE) $(LIB_DESTDIR)/$(TARGETA) $(libdir) + $(COPY_FILE) $(LIB_DESTDIR)/$(TARGET0) $(libdir) + $(COPY_FILE) $(LIB_DESTDIR)/$(TARGET1) $(libdir) + $(COPY_FILE) $(LIB_DESTDIR)/$(TARGET2) $(libdir) + $(COPY_FILE) $(LIB_DESTDIR)/$(TARGETD) $(libdir) + test -d $(includedir) || mkdir -p $(includedir) + $(COPY_FILE) $(LIB_DESTDIR)/* $(libdir) + $(COPY_FILE) $(INCLUDE) $(includedir) + +#uninstall: delete all the installed files--the copies that the `install' target creates. +uninstall: + #For library uninstall + $(DEL_FILE) $(libdir)/$(TARGETA) + $(DEL_FILE) $(libdir)/$(TARGETD) + $(DEL_FILE) $(libdir)/$(TARGET0) + $(DEL_FILE) $(libdir)/$(TARGET1) + $(DEL_FILE) $(libdir)/$(TARGET2) + $(DEL_FILE) $(addprefix $(includedir)/, $(notdir $(INCLUDE))) + diff --git a/examples/README b/examples/README new file mode 100644 index 0000000000000000000000000000000000000000..8142a4d29bf2d67b28517a8aaccf21ee589518bd --- /dev/null +++ b/examples/README @@ -0,0 +1,42 @@ +DISTRIBUTION +The directory of this distribution of PacketLib are: +- doc: containing the documentation of the PacketLib (Reference Manual, Interface Control Document and Programmer's Guide) +- examples: some examples and some PacketLib configuration files, used in the Interface Control Document and in the Programmer's Guide. +- include: the include files of the library. +- lib: static and dynamic binary library +- model: a Rational Rose file with the UML model of the library +- ref/html the doxygen documentation of the library (same content of the Reference Manual) + +HOW TO INSTALL PACKETLIB +To install PacketLib: + +make install + +and the include and lib files will be copied in the /usr/local/include and /usr/local/lib (need root permission). +If you want to change the installation path use + +make prefix='newpath' install + +but it is necessary to add newpath in the LD_LIBRARY_PATH environment variable anche change the include path of the Makefile (-I option of the compiler). + +UNINSTALL THE PACKETLIB +To uninstall the PacketLib + +make uninstall + +or + +make prefix='installation_path' uninstall + +EXAMPLES +Use + +make + +to build the examples in the examples directory. + +make clean + +if you want to clean the file built. + +The description of the examples are present in the Programmer's Guide, in the section of the examples. \ No newline at end of file diff --git a/examples/examples/config_files/39_01.packet b/examples/examples/config_files/39_01.packet new file mode 100755 index 0000000000000000000000000000000000000000..49aa8c253223dabce10af343ce21a4ab9187583d --- /dev/null +++ b/examples/examples/config_files/39_01.packet @@ -0,0 +1,241 @@ +-- name of packet +39.01 +[PacketHeader] +-- file in cui e' presente la descrizione dell'header +headerESATM.header +[DataFieldHeader] +-- field 0 +Sync Marker MSB +16 +65499 +-- field 1 +Sync Marker LSB +16 +37461 +-- field 2 +CRC flag +2 +0b11 +-- field 3 +Packet Type +6 +none +-- field 4 +Packet Subtype +8 +1 +-- field 5 +MM Page ID +16 +none +--field 6 +MM Packet Counter +16 +none +--field 7 +Century +8 +32 +--field 8 +APID Sequence Counter +8 +nome +--field 9 +OBT12 +8 +none +--field 10 +OBT13 +8 +none +--field 11 +OBT14 +8 +none +--field 12 +OBT15 +8 +none +--field 13 +OBT16 +8 +none +--field 14 +Not used +4 +0 +--field 15 +OBT17 +4 +none +--field 16 +OBT18 +8 +none +--field 17 +OBT19 +8 +none +--field 18 +Mode +8 +none +--field 19 +Pkt. Struct ID +4 +1 +-- field 20 +Redundancy ID +4 +1 +[SourceDataField] +-- type of packet: noblock, block, rblock (with recoursive block) +rblock +[RBlock Configuration] +-- fixed part present (yes | no) +yes +-- variable part present (yes | no). If yes, add [RBlockX] sections. +yes +--number of rblock (if variable part is present) +1 +[Fixed Part] +--field 0 - SOURCE DATA FIELD HEADER ---------------------------------------- +Quaternion 1H +16 +none +--field 1: parte bassa del float +Quaternion 1L +16 +none +--field 2: parte alta del float +Quaternion 2H +16 +none +--field 3: parte bassa del float +Quaternion 2L +16 +none +--field 4: parte alta del float +Quaternion 3H +16 +none +--field 5: parte bassa del float +Quaternion 3L +16 +none +--field 6: parte alta del float +Quaternion 4H +16 +none +--field 7: parte bassa del float +Quaternion 4L +16 +none +--field 8: parte alta +GPS Position XH +16 +none +--field 9: parte bassa +GPS Position XL +16 +none +--field 10: parte alta +GPS Position YH +16 +none +--field 11: parte bassa +GPS Position YL +16 +none +--field 12: parte alta +GPS Position ZH +16 +none +--field 13: parte bassa +GPS Position ZL +16 +none +--field 14 +Spare OCID +4 +0 +--field 15 +Orbital phase +2 +none +--field 16 +Recovery sub-phase +1 +none +--field 17 +Grid configuration mode +4 +none +--field 18 +LUT 3/4 X +3 +none +--field 19 +LUT 3/4 Z: H +2 +none +--field 20 +LUT 3/4 Z: L +1 +none +--field 21 +LUT AC +3 +none +--field 22 +LUT R-TRIGGER +3 +none +--field 23 +LUT DIS +3 +none +--field 24 +LUT COEF +3 +none +--field 25 +LUT C-DIS +3 +none +--field 26 (Number of grid events 1<=n<=73) +Number of Events +16 +none +[RBlock1] +--type of number of blocks of this variable part: fixed = number of block fixed equals to max number of block (fixed | variable) +variable +--number of blocks for fixed value into variable part, max number of blocks for variable value into variable part (73) +73 +-- for variable block, number of level of headers in which is present the field with the number of blocks of the variable part (0: fixed part) +0 +-- for variable block, index of field of the header which rappresent the number of events (the number of blocks) of the packet +26 +-- for variable block, valore da sommare per ottenere il numero di eventi (blocchi) reali +0 +rblock_type_E.rblock +[Identifiers] +-- ID0 APID +-- field number +3 +-- type (0 header, 1 data field) +0 +-- value +767 +-- ID1 type +3 +1 +39 +-- ID2 subtype +4 +1 +1 +[Tail] +CRC +16 +none diff --git a/examples/examples/config_files/BURST.packet b/examples/examples/config_files/BURST.packet new file mode 100755 index 0000000000000000000000000000000000000000..aac751f3ff2ca7b83298451cd4bb1e018b917745 --- /dev/null +++ b/examples/examples/config_files/BURST.packet @@ -0,0 +1,125 @@ +-- name of packet +BURST events (LAYOUT 3) +[PacketHeader] +-- file in cui e' presente la descrizione dell'header +headerESATM.header +[DataFieldHeader] +-- field 0 +Spare +6 +none +-- field 1 +Checksum flag +2 +none +-- field 2 +Packet Type +4 +none +-- field 3 +Packet subtype +4 +none +-- field 4 +Time Tag second (MSB) +16 +none +-- field 5 +Time Tag second (LSB) +16 +none +-- field 6 +Time Tag millisecond +16 +none +-- field 7 +Spare +12 +none +-- field 8 +Nevents +4 +none +[SourceDataField] +block +variable +--type of number of block: fixed = number of block fixed equals to max number of block (fixed | variable) +variable +--supposed number (or max number) of block +79 +--index of field in the [DataFieldHeader] section wich rappresent the number of event (the number of block) of the packet +8 +-- offset to be added to the value given by the field m of the Data Field Header in order to obtain the correct value of the number of blocks +0 +[SourceDataFieldBlockFixed] +-- number (or max number) of element +32 +-- index of field in the [SourceDataFieldBlockFixed] section wich rappresent the number of element (the number of bar) of the block +2 +-- valore da sommare per ottenere il numero di element reali +1 +-- field 0 +1 +1 +none +-- field 1 +spare +10 +none +-- field 2 +Number of bars - 1 +5 +none +-- field 3 +TE Internal Counter (MSB) +16 +none +-- field 4 +TE Internal Counter (LSB) +16 +none +[SourceDataFieldBlockVariable] +-- field 0 +0 +1 +0 +-- field 1 +0 +1 +0 +-- field 2 +Bar ID (2 MSB) +2 +none +-- field 3 +PDA PHA (12 bits) +12 +none +-- field 4 +0 +1 +0 +-- field 5 +Bar ID (3 LSB) +3 +none +-- field 6 +PDB PHA (12 bits) +12 +none +[Identifiers] +-- id0 APID +-- field number +3 +-- type (0 header, 1 data field) +0 +-- value +1294 +--id1 type +2 +1 +15 +--id2 subtype +3 +1 +3 diff --git a/examples/examples/config_files/BURST.stream b/examples/examples/config_files/BURST.stream new file mode 100755 index 0000000000000000000000000000000000000000..b696da130ada640a35800a611fd35cd9c66fb438 --- /dev/null +++ b/examples/examples/config_files/BURST.stream @@ -0,0 +1,13 @@ +[Configuration] +--prefix +true +--stream format bigendian +true +--dimension of prefix +2 +[Header Format] +headerESATM.header +[Packet Format] +BURST.packet +TC_start.packet +TC_stop.packet diff --git a/examples/examples/config_files/CVS/Entries b/examples/examples/config_files/CVS/Entries new file mode 100644 index 0000000000000000000000000000000000000000..3426b4ba9d670f1a0685893189977f654a5e7f24 --- /dev/null +++ b/examples/examples/config_files/CVS/Entries @@ -0,0 +1,15 @@ +/39_01.packet/1.1/Wed Mar 9 10:57:15 2005// +/BURST.packet/1.1/Wed Mar 9 10:57:15 2005// +/BURST.stream/1.1/Wed Mar 9 10:57:15 2005// +/GRID.01.packet/1.1/Wed Mar 9 10:57:15 2005// +/GRID.stream/1.1/Wed Mar 9 10:57:15 2005// +/TC_start.packet/1.1/Wed Mar 9 10:57:15 2005// +/TC_stop.packet/1.1/Wed Mar 9 10:57:15 2005// +/headerESATC.header/1.1/Wed Mar 9 10:57:15 2005// +/headerESATM.header/1.1/Wed Mar 9 10:57:15 2005// +/p3901.stream/1.1/Wed Mar 9 10:57:15 2005// +/rblock_type_0_1.rblock/1.1/Wed Mar 9 10:57:15 2005// +/rblock_type_2.rblock/1.1/Wed Mar 9 10:57:15 2005// +/rblock_type_3.rblock/1.1/Wed Mar 9 10:57:15 2005// +/rblock_type_E.rblock/1.1/Wed Mar 9 10:57:15 2005// +D diff --git a/examples/examples/config_files/CVS/Repository b/examples/examples/config_files/CVS/Repository new file mode 100644 index 0000000000000000000000000000000000000000..3ad16f50f7dd18fea27485472796ffa1ba393ab8 --- /dev/null +++ b/examples/examples/config_files/CVS/Repository @@ -0,0 +1 @@ +PacketLib/packetlib/examples/config_files diff --git a/examples/examples/config_files/CVS/Root b/examples/examples/config_files/CVS/Root new file mode 100644 index 0000000000000000000000000000000000000000..90ebd71d1803de028366c2252e5f492c965aee2b --- /dev/null +++ b/examples/examples/config_files/CVS/Root @@ -0,0 +1 @@ +:pserver:bulgarelli@gtb.iasfbo.inaf.it:/home/repository/cvs/gtb diff --git a/examples/examples/config_files/GRID.01.packet b/examples/examples/config_files/GRID.01.packet new file mode 100755 index 0000000000000000000000000000000000000000..6700aa11cb9ad2ead1861be4fac3e7a7f47b145a --- /dev/null +++ b/examples/examples/config_files/GRID.01.packet @@ -0,0 +1,477 @@ +-- name of packet +GRID events (LAYOUT 2) +[PacketHeader] +-- file in cui e' presente la descrizione dell'header +headerESATM.header +[DataFieldHeader] +-- field 0 +TM_VERSION +2 +1 +-- field 1 +Spare +3 +0 +-- field 2: 0 NO, 1 YES +EXT_TIME_TAG +1 +none +-- field 3 +Checksum flag +2 +0 +-- field 4 +Packet Type +4 +none +-- field 5 +Packet subtype +4 +none +-- field 6 +Time Tag second (MSB) +16 +none +-- field 7 +Time Tag second (LSB) +16 +none +-- field 8 +Time Tag millisecond +16 +none +-- field 9 +Spare +12 +0 +-- field 10 +Nevents +4 +none +[SourceDataField] +block +fixed +--type of number of block: fixed = number of block fixed equals to max number of block (fixed | variable) +variable +--supposed number (or max number) of block +7 +--index of field in the [DataFieldHeader] section wich rappresent the number of event (the number of block) of the packet +10 +-- offset to be added to the value given by the field m of the Data Field Header in order to obtain the correct value of the number of blocks +0 +[SourceDataFieldBlock] +-- field 0: OBT (preso da scheda BURST) +TE Internal Counter (MSB) +16 +none +-- field 1: OBT +TE Internal Counter (LSB) +16 +none +-- bar 01 +-- EXT_TIME: counter preso da scheda esterna per sincronizzazione con Acquisition System di INFN/TS +MSB_EXT_TIME_1 +4 +none +Bar 01 PDA PHA (12 bits) +12 +none +MSB_EXT_TIME_2 +4 +none +Bar 01 PDB PHA (12 bits) +12 +none +-- bar 02 +LSB_EXT_TIME_1 +4 +none +Bar 02 PDA PHA (12 bits) +12 +none +LSB_EXT_TIME_2 +4 +none +Bar 02 PDB PHA (12 bits) +12 +none +-- bar 03 +spare +4 +0 +Bar 03 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 03 PDB PHA (12 bits) +12 +none +-- bar 04 +spare +4 +0 +Bar 04 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 04 PDB PHA (12 bits) +12 +none +-- bar 05 +spare +4 +0 +Bar 05 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 05 PDB PHA (12 bits) +12 +none +-- bar 06 +spare +4 +0 +Bar 06 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 06 PDB PHA (12 bits) +12 +none +-- bar 07 +spare +4 +0 +Bar 07 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 07 PDB PHA (12 bits) +12 +none +-- bar 08 +spare +4 +0 +Bar 08 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 08 PDB PHA (12 bits) +12 +none +-- bar 09 +spare +4 +0 +Bar 09 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 09 PDB PHA (12 bits) +12 +none +-- bar 10 +spare +4 +0 +Bar 10 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 10 PDB PHA (12 bits) +12 +none +-- bar 11 +spare +4 +0 +Bar 11 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 11 PDB PHA (12 bits) +12 +none +-- bar 12 +spare +4 +0 +Bar 12 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 12 PDB PHA (12 bits) +12 +none +-- bar 13 +spare +4 +0 +Bar 13 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 13 PDB PHA (12 bits) +12 +none +-- bar 14 +spare +4 +0 +Bar 14 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 14 PDB PHA (12 bits) +12 +none +-- bar 15 +spare +4 +0 +Bar 15 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 15 PDB PHA (12 bits) +12 +none +-- bar 16 +spare +4 +0 +Bar 16 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 16 PDB PHA (12 bits) +12 +none +-- bar 17 +spare +4 +0 +Bar 17 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 17 PDB PHA (12 bits) +12 +none +-- bar 18 +spare +4 +0 +Bar 18 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 18 PDB PHA (12 bits) +12 +none +-- bar 19 +spare +4 +0 +Bar 19 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 19 PDB PHA (12 bits) +12 +none +-- bar 20 +spare +4 +0 +Bar 20 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 20 PDB PHA (12 bits) +12 +none +-- bar 21 +spare +4 +0 +Bar 21 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 21 PDB PHA (12 bits) +12 +none +-- bar 22 +spare +4 +0 +Bar 22 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 22 PDB PHA (12 bits) +12 +none +-- bar 23 +spare +4 +0 +Bar 23 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 23 PDB PHA (12 bits) +12 +none +-- bar 24 +spare +4 +0 +Bar 24 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 24 PDB PHA (12 bits) +12 +none +-- bar 25 +spare +4 +0 +Bar 25 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 25 PDB PHA (12 bits) +12 +none +-- bar 26 +spare +4 +0 +Bar 26 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 26 PDB PHA (12 bits) +12 +none +-- bar 27 +spare +4 +0 +Bar 27 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 27 PDB PHA (12 bits) +12 +none +-- bar 28 +spare +4 +0 +Bar 28 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 28 PDB PHA (12 bits) +12 +none +-- bar 29 +spare +4 +0 +Bar 29 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 29 PDB PHA (12 bits) +12 +none +-- bar 30 +spare +4 +0 +Bar 30 PDA PHA (12 bits) +12 +none +spare +4 +0 +Bar 30 PDB PHA (12 bits) +12 +none +[Identifiers] +-- id0 APID +-- field number +3 +-- type (0 header, 1 data field) +0 +-- value +1294 +--id1 type +4 +1 +15 +--id2 subtype +5 +1 +1 diff --git a/examples/examples/config_files/GRID.stream b/examples/examples/config_files/GRID.stream new file mode 100755 index 0000000000000000000000000000000000000000..555cb4ec0cb8ae0737ca22cb9be114db6e38c043 --- /dev/null +++ b/examples/examples/config_files/GRID.stream @@ -0,0 +1,15 @@ +[Configuration] +--prefix +true +--input format bigendian +true +--dimension of prefix +2 +[Header Format] +headerESATM.header +[Packet Format] +GRID.01.packet +TC_CAL_start.packet +TC_CAL_stop.packet + + diff --git a/examples/examples/config_files/TC_start.packet b/examples/examples/config_files/TC_start.packet new file mode 100755 index 0000000000000000000000000000000000000000..eebf594a9674a84ac7f57f830bf0902f2d77c5da --- /dev/null +++ b/examples/examples/config_files/TC_start.packet @@ -0,0 +1,50 @@ +-- name of packet +TC Packet: start (LAYOUT 1) +[PacketHeader] +-- file in cui e' presente la descrizione dell'header +headerESATC.header +[DataFieldHeader] +--field 0 +Spare +2 +0b00 +-- field 1 +Checksum type +2 +0b00 +-- field 2 +ACK +4 +0b00 +-- field 3 +Packet type +4 +5 +-- field 4 +Packet subtype +4 +5 +[SourceDataField] +noblock +fixed +[SourceDataFieldList] +TC Application Data +16 +512 +[Identifiers] +-- id0 APID +3 +0 +257 +--id1 type +3 +1 +5 +--id2 subtype +4 +1 +5 +-- id3 command +0 +2 +512 diff --git a/examples/examples/config_files/TC_stop.packet b/examples/examples/config_files/TC_stop.packet new file mode 100755 index 0000000000000000000000000000000000000000..60eab3ea9d94e53ecddc294c7ec3fd88d1d7cfa7 --- /dev/null +++ b/examples/examples/config_files/TC_stop.packet @@ -0,0 +1,50 @@ +-- name of packet +TC Packet: stop +[PacketHeader] +-- file in cui e' presente la descrizione dell'header +headerESATC.header +[DataFieldHeader] +--field 0 +Spare +2 +0b00 +-- field 1 +Checksum type +2 +0b00 +-- field 2 +ACK +4 +0b00 +-- field 3 +Packet type +4 +5 +-- field 4 +Packet subtype +4 +5 +[SourceDataField] +noblock +fixed +[SourceDataFieldList] +TC Application Data +16 +0 +[Identifiers] +-- id0 APID +3 +0 +257 +--id1 type +3 +1 +5 +--id2 subtype +4 +1 +5 +-- id3 command +0 +2 +0 diff --git a/examples/examples/config_files/headerESATC.header b/examples/examples/config_files/headerESATC.header new file mode 100755 index 0000000000000000000000000000000000000000..f1a88e984641cdd2b98cb6e80be071538c1c75dc --- /dev/null +++ b/examples/examples/config_files/headerESATC.header @@ -0,0 +1,33 @@ +-- name of header +Header ESA standard +-- number of field with dimension of packet +6 +[Field] +-- field 0 +Version number +3 +0b001 +-- field 1 +Type +1 +0b1 +-- field 2 +DHFH +1 +0b1 +-- field 3 +APID +11 +none +-- field 4 +SF +2 +0b11 +-- field 5 +Source Sequence Counter +14 +none +-- field 6 +Packet Length +16 +none diff --git a/examples/examples/config_files/headerESATM.header b/examples/examples/config_files/headerESATM.header new file mode 100755 index 0000000000000000000000000000000000000000..55ae80ab3050bbd86732ad8d29ac39993753d14b --- /dev/null +++ b/examples/examples/config_files/headerESATM.header @@ -0,0 +1,33 @@ +-- name of header +Header ESA standard +-- number of field with dimension of packet +6 +[Field] +-- field 0 +Version number +3 +0b100 +-- field 1 +Type +1 +0b0 +-- field 2 +DHFH +1 +0b1 +-- field 3 +APID +11 +none +-- field 4 +SF +2 +0b11 +-- field 5 +Source Sequence Counter +14 +none +-- field 6 +Packet Length +16 +none diff --git a/examples/examples/config_files/p3901.stream b/examples/examples/config_files/p3901.stream new file mode 100755 index 0000000000000000000000000000000000000000..4d08708dcefc09cf76f368171e16cde05522084b --- /dev/null +++ b/examples/examples/config_files/p3901.stream @@ -0,0 +1,13 @@ +[Configuration] +--prefix +true +--stream format bigendian +true +--dimension of prefix +2 +[Header Format] +headerESATM.header +[Packet Format] +39_01.packet +TC_start.packet +TC_stop.packet diff --git a/examples/examples/config_files/rblock_type_0_1.rblock b/examples/examples/config_files/rblock_type_0_1.rblock new file mode 100755 index 0000000000000000000000000000000000000000..3d21980f0afbac3f0476d50ef9ff646e9f647c7c --- /dev/null +++ b/examples/examples/config_files/rblock_type_0_1.rblock @@ -0,0 +1,46 @@ +[RBlock Configuration] +-- fixed part present (yes | no) +yes +-- variable part present (yes | no) +no +[Fixed Part] +-- field 0 +FEB +4 +none +-- field 1 +CHIP +5 +none +-- field 2 +Strip address +7 +none +-- field 3 +Total charge compressed value +16 +none +-- field 4 +Total width +8 +none +-- field 5 +Central strip charge (XSTRIPC3) +8 +none +-- field 6 +Left strip charge (central strip - 2) (XSTRIPC1) +8 +none +-- field 7 +Left strip charge (central strip - 1) (XSTRIPC2) +8 +none +-- field 8 +Right strip charge (central strip + 1) (XSTRIPC4) +8 +none +-- field 9 +Right strip charge (central strip + 2) (XSTRIPC5) +8 +none diff --git a/examples/examples/config_files/rblock_type_2.rblock b/examples/examples/config_files/rblock_type_2.rblock new file mode 100755 index 0000000000000000000000000000000000000000..19c421a7d7841f85fa4bf055b09255e3a64844f4 --- /dev/null +++ b/examples/examples/config_files/rblock_type_2.rblock @@ -0,0 +1,26 @@ +[RBlock Configuration] +-- fixed part present (yes | no) +yes +-- variable part present (yes | no) +no +[Fixed Part] +-- field 0 +Spare +3 +0 +-- field 1 +Bar ID +5 +none +-- field 2 +Energy Side B +8 +none +-- field 3 +Energy Side B +4 +none +-- field 4 +Energy Side A +12 +none \ No newline at end of file diff --git a/examples/examples/config_files/rblock_type_3.rblock b/examples/examples/config_files/rblock_type_3.rblock new file mode 100755 index 0000000000000000000000000000000000000000..b3c8a8832fccb11ee65d34d757a128133ff2c2e8 --- /dev/null +++ b/examples/examples/config_files/rblock_type_3.rblock @@ -0,0 +1,18 @@ +[RBlock Configuration] +-- fixed part present (yes | no) +yes +-- variable part present (yes | no) +no +[Fixed Part] +-- field 0 +Spare +7 +0 +-- field 1 +FEB Addr. +4 +none +-- field 2 +Chip Addr. +5 +none diff --git a/examples/examples/config_files/rblock_type_E.rblock b/examples/examples/config_files/rblock_type_E.rblock new file mode 100755 index 0000000000000000000000000000000000000000..7a21826f759174e2a9a40c2c8f9aab654735012f --- /dev/null +++ b/examples/examples/config_files/rblock_type_E.rblock @@ -0,0 +1,176 @@ +[RBlock Configuration] +-- fixed part present (yes | no) +yes +-- variable part present (yes | no). If yes, add [RBlockX] sections. +yes +--number of rblock (if variable part is present) +4 +[Fixed Part] +-- field 0 +Spare +3 +0 +-- field 1 +MCAL valid +1 +none +-- field 2 +Number of cluster X elements +6 +none +-- field 3 +Number of cluster Z elements +6 +none +-- field 4 +Spare +3 +0 +-- field 5 +Number of zero-suppressed elements +5 +none +-- field 6 +Number of extra-fired elements +8 +none +-- field 7 +Spare +1 +0 +-- field 8 +Time Tag MSW: second, H +15 +none +-- field 9 +Time Tag mSW: second, L +12 +none +-- field 10 +Microseconds, H +4 +none +-- field 11 +Time Tag LSW: microseconds, L +16 +none +-- field 12: OBTCORR +OBT Correction +16 +none +-- field 13: ACTOPCON + ACLATCON + MCAL_HT: ACL11, ACL10, ..., ACL0, ACT2, ACT1, ACT0, MHT +Configuration (Top&Lat) +16 +none +-- field 14 +S 1 MGO +8 +none +-- field 15 +S 1 Upper thres +8 +none +-- field 16 +S 2 MGO +8 +none +-- field 17 +S 2 Upper thres +8 +none +-- field 18 +Spare +8 +none +-- field 19 +Spare +2 +0 +-- field 20 +F_ht +1 +none +-- field 21 +F_burst +1 +none +-- field 22 +F_st +1 +none +-- field 23 +F_bkg +1 +none +-- field 24 +F_mcal +1 +none +-- field 25 +F_ac +1 +none +-- field 26 +Spare +4 +0 +-- field 27 +FVC X Vector +12 +none +-- field 28 +Spare +4 +0 +-- field 29 +FVC Z Vector +12 +1 +[RBlock1] +--type of number of blocks of this variable part: fixed = number of block fixed equals to max number of block (fixed | variable) +variable +--number of blocks for fixed value into variable part, max number of blocks for variable value into variable part (48) +48 +-- for variable block, number of level of headers in which is present the field with the number of blocks of the variable part (0: fixed part) +0 +-- for variable block, index of field which rappresent the number of event (the number of block) of the packet +2 +-- for variable block, valore da sommare per ottenere il numero di eventi (blocchi) reali +0 +rblock_type_0_1.rblock +[RBlock2] +--type of number of blocks of this variable part: fixed = number of block fixed equals to max number of block (fixed | variable) +variable +--number of blocks for fixed value into variable part, max number of blocks for variable value into variable part (48) +48 +-- for variable block, number of level of headers in which is present the field with the number of blocks of the variable part (0: fixed part) +0 +-- for variable block, index of field which rappresent the number of event (the number of block) of the packet +3 +-- for variable block, valore da sommare per ottenere il numero di eventi (blocchi) reali +0 +rblock_type_0_1.rblock +[RBlock3] +--type of number of blocks of this variable part: fixed = number of block fixed equals to max number of block (fixed | variable) +variable +--number of blocks for fixed value into variable part, max number of blocks for variable value into variable part (30) +30 +-- for variable block, number of level of headers in which is present the field with the number of blocks of the variable part (0: fixed part) +0 +-- for variable block, index of field which rappresent the number of event (the number of block) of the packet +5 +-- for variable block, valore da sommare per ottenere il numero di eventi (blocchi) reali +0 +rblock_type_2.rblock +[RBlock4] +--type of number of blocks of this variable part: fixed = number of block fixed equals to max number of block (fixed | variable) +variable +--number of blocks for fixed value into variable part, max number of blocks for variable value into variable part (192) +192 +-- for variable block, number of level of headers in which is present the field with the number of blocks of the variable part (0: fixed part) +0 +-- for variable block, index of field which rappresent the number of event (the number of block) of the packet +6 +-- for variable block, valore da sommare per ottenere il numero di eventi (blocchi) reali +0 +rblock_type_3.rblock diff --git a/examples/socketin.cpp b/examples/examples/in.cpp similarity index 100% rename from examples/socketin.cpp rename to examples/examples/in.cpp diff --git a/examples/msgqclient.cpp b/examples/examples/msgqclient.cpp similarity index 100% rename from examples/msgqclient.cpp rename to examples/examples/msgqclient.cpp diff --git a/examples/msgqserver.cpp b/examples/examples/msgqserver.cpp similarity index 100% rename from examples/msgqserver.cpp rename to examples/examples/msgqserver.cpp diff --git a/examples/socketout.cpp b/examples/examples/out.cpp similarity index 100% rename from examples/socketout.cpp rename to examples/examples/out.cpp diff --git a/examples/TestSHMClient.cpp b/examples/examples2/TestSHMClient.cpp similarity index 100% rename from examples/TestSHMClient.cpp rename to examples/examples2/TestSHMClient.cpp diff --git a/examples/TestSHMServer.cpp b/examples/examples2/TestSHMServer.cpp similarity index 100% rename from examples/TestSHMServer.cpp rename to examples/examples2/TestSHMServer.cpp diff --git a/examples/examples2/main.cpp b/examples/examples2/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3a93f85e17d3682d0abbb7ab85dfcbbaece18c0a --- /dev/null +++ b/examples/examples2/main.cpp @@ -0,0 +1,726 @@ +#include "Device.h" +#include "Utility.h" +//#include "PacketLibDefinition.h" +#include +#include "InputPacketStream.h" +#include "SDFRBBlock.h" +#include "OutputSocketClient.h" +#include "OutputPacketStream.h" +#include "ByteStream.h" +#include "Output.h" +#include "OutputFile.h" +#include "InputSocketServer.h" +#include "InputPacketStream.h" +#include "InputPacketStreamFile.h" +#include "Input.h" +#include "InputFile.h" +#include "PacketLibDemo.h" +#include "SDFBlockVariable.h" +#include "SDFBlockFixed.h" +#include +#define APIDTM 767 +using namespace PacketLib; +using namespace std; + +int mainA() { + InputPacketStreamFile* ips = new InputPacketStreamFile(); + ips->setFileNameConfig("bugs/4/CAL-DFE-TE.stream"); + ips->createStreamStructure(); + + ips->setFileNameStream("bugs/4/mcal.raw"); + ips->setInitialPosition(0); + ips->openInputStream(); + + ips->freeRun(); + + list byteStreamPacketList; + + for(int index=0; index< ips->getNumberOfFileStreamPointer(); index++) + { + Packet *p = ips->getPacketFromFileStreamPointer(index); + int apid = p->header->getFieldValue(3); + if (apid == 1294) { + //make a copy of the byte stream + ByteStream *b = new ByteStream(p->packet, 0, 0); + byteStreamPacketList.push_back(b); + } + + } + list::const_iterator iter; + // Iterate through list and output each element. + int i = 0; + for (iter=byteStreamPacketList.begin(); iter != byteStreamPacketList.end(); iter++) + { + ByteStream* b = (ByteStream*)(*iter); + + Packet* p = ips->getPacketType(3); + cout << p->getName() << " " << b->getDimension() << endl; + bool ok = p->setAndVerifyPacketValue(0, b); + if(ok) { + cout << p->header->getFieldValue(5) << endl; //get the source sequence counter + } + + } + +} + +int main() { + InputPacketStreamFile* ips = new InputPacketStreamFile(); + ips->setFileNameConfig("bugs/4/CAL-DFE-TE.stream"); + ips->createStreamStructure(); + + ips->setFileNameStream("bugs/4/mcal.raw"); + ips->setInitialPosition(0); + ips->openInputStream(); + + ips->freeRun(); + + list fileStreamList; + + for(int index=0; index< ips->getNumberOfFileStreamPointer(); index++) + { + Packet *p = ips->getPacketFromFileStreamPointer(index); + int apid = p->header->getFieldValue(3); + if (apid == 1294) { + //make a copy of the byte stream + FileStreamPointer* fsp = ips->getFileStreamPointer(index); + fileStreamList.push_back(fsp); + } + + } + list::const_iterator iter; + // Iterate through list and output each element. + int i = 0; + for (iter=fileStreamList.begin(); iter != fileStreamList.end(); iter++) + { + FileStreamPointer* fsp = (FileStreamPointer*)(*iter); + + Packet *p = ips->getPacketFromFileStreamPointer(fsp->index); + cout << p->getName() << endl; + } + +} + +int mainrrr() { + InputPacketStreamFile* ips = new InputPacketStreamFile(); + ips->setFileNameConfig("bugs/4/CAL-DFE-TE.stream"); + ips->createStreamStructure(); + + + ips->setFileNameStream("bugs/4/mcal.raw"); + ips->setInitialPosition(0); + ips->openInputStream(); + + ips->freeRun(); + + list packetList; + + for(int index=0; index< ips->getNumberOfFileStreamPointer(); index++) + { + Packet *p = ips->getPacketFromFileStreamPointer(index, true); + int apid = p->header->getFieldValue(3); + if (apid == 1294) { + packetList.push_back( p ); + if(index == 300) + break; + } + + } + list::const_iterator iter; + // Iterate through list and output each element. + for (iter=packetList.begin(); iter != packetList.end(); iter++) + { + Packet* p = (Packet*)(*iter); + cout << p->getName() << endl; + + } + sleep(30); + +} + + +int maingrid() { + + + +Output* out; + OutputPacketStream ops; +SDFRBBlock* bi, *bcX, *bcZ, *TAA1, *mcal; + + //create the structure + ops.setFileNameConfig("bugs/tail/p3901.stream"); + ops.createStreamStructure(); + + //parameter for output: file + out = (Output*) new OutputFile(ops.isBigEndian()); + char** param = (char**) new char* [2]; + param[0] = "./test.raw"; //nome file + param[1] = 0; + + //open the output + out->open(param); + + ops.setOutput(out); + + //send a TM packet + Packet* p = ops.getPacketType(1); + + cout << p->dataField->sourceDataField->getNumberOfFields() << endl; + + + p->header->setFieldValue(3, APIDTM); + //Get a pointer to the source data field + SDFRBlock* sdf = (SDFRBlock*) p->dataField->sourceDataField; + + int block_3901_events = 1; + int block_3901_1 = 1; + int block_3901_2 = 1; + int block_3901_3 = 1; + int block_3901_4 = 1; + //set the number of blocks of the sdf + sdf->setNumberOfRealDataBlock(block_3901_events, 0); //N blocks for rtype 0 + //for each block of the sdf, set the number of sub-blocks + for(int i=0; i < block_3901_events; i++) { + //get the block i of type 0 of the source data field + bi = sdf->getBlock(i, 0); + //set the number of blocks of sub-block of type 0 of block i of the sdf + bi->setNumberOfRealDataBlock(block_3901_1, 0); + //set the number of blocks of sub-block of type 1 of block i of the sdf + bi->setNumberOfRealDataBlock(block_3901_2, 1); + //set the number of blocks of sub-block of type 2 of block i of the sdf + bi->setNumberOfRealDataBlock(block_3901_3, 2); + //set the number of blocks of sub-block of type 3 of block i of the sdf + bi->setNumberOfRealDataBlock(block_3901_4, 3); + } + + //-------------------------------------------------------- + //set the data field header values ----------------------- + //-------------------------------------------------------- + p->dataField->dataFieldHeader->setFieldValue(3, 39); //type: the value 39 in the field 3 + p->dataField->dataFieldHeader->setFieldValue(4, 1); //subtype + p->dataField->tail->setFieldValue(0, 13); + cout << "sdf num of fields " << p->dataField->sourceDataField->getNumberOfFields() << endl; + cout << "sdf dimension " << p->dataField->sourceDataField->getDimension() << endl; +/* char** cc = p->dataField->sourceDataField->printValue(); + int num=0; + while(cc[num] != 0) { + cout << cc[num] << endl; + num++; + }*/ + ByteStream* b = p->getOutputStream(); + ops.writePacket(p); + out->close(); +} + +int main5() { +Input* in; + try { + InputPacketStreamFile* ips = new InputPacketStreamFile(); + ByteStream* bs; + bool endcycle = false; + + //create the structure + ips->setFileNameConfig("bugs/tail/p3901.stream"); + ips->createStreamStructure(); + ips->setFileNameStream("bugs/tail/TM3901.raw"); + ips->setInitialPosition(0); + ips->openInputStream(); + ips->freeRun(); + Packet *p = ips->getPacketFromFileStreamPointer(0); + cout << p->printSourceDataFieldStream() << endl; + cout << p->dataField->sourceDataField->stream->printStreamInHexadecimal() << endl; + cout << p->dataField->tail->getFieldValue(0) << endl; + return 0; + + + File* filepacket = new File(true); + + filepacket->open("bugs/tail/TM3901.raw", "r"); + + cout << ips->packetLibVersion() << endl; + + cout << "INPUT: FILE" << endl; + + ByteStream* b0, *b1, *b2; + //BufferByteStream *br = new BufferByteStream; + + //filepacket->memBookmarkPos(); + int i=0; + while(!filepacket->isEOF()) { + if(ips->thereIsPrefix()) //si scarta il prefix + b0 = filepacket->getNByte(ips->getPrefixDimension()); + else + b0 = 0; + int dimheader = ips->headerReference->getDimension(); + b1 = filepacket->getNByte(dimheader); + ips->headerReference->setByteStream(b1); + word pl = ips->headerReference->getPacketLength(); + + //filepacket->setLastBookmarkPos(); + + //b2 = filepacket->getNByte(ips->getDimPrefix() + dimheader + pl); + b2 = filepacket->getNByte(pl); + cout << b2->printStreamInHexadecimal() << endl; + i++; + if(i==10) return 1; + } + +} catch (PacketException* e) { + cout << e->geterror() << endl; +} +} + + + +int readpacket(char* filename); + +int main3 () { +try { + cout << time(0) << endl; + Output* out; + OutputPacketStream ops; + char* filename = "bugs/3/config_files/conf.stream"; + //create the structure + ops.setFileNameConfig(filename); + ops.createStreamStructure(); + + //parameter for output: file + out = (Output*) new OutputFile(ops.isBigEndian()); + char** param = (char**) new char* [2]; + param[0] = "./test.raw"; //nome file + param[1] = 0; + + //open the output + out->open(param); + + ops.setOutput(out); + + // TM packet + Packet* p = ops.getPacketType(1); + + // Set header section + p->header->setFieldValue(3, 1113); + + // Set datation section + p->dataField->dataFieldHeader->setFieldValue(3, 516); // Number Of Week + p->dataField->dataFieldHeader->setFieldValue_3_14(4, 66578); // Seconds of Week + p->dataField->dataFieldHeader->setFieldValue(6, 125); // Internal Timer Value + p->dataField->dataFieldHeader->setFieldValue(7, 23); // Counter 1/32 Hz + p->dataField->dataFieldHeader->setFieldValue(8, 56); // Counter 1 Hz + + // Number of blocks is fixed + p->dataField->setNumberOfRealDataBlock(268); + + // set data fields + p->dataField->dataFieldHeader->setFieldValue(9, 45631); // WINDOWID + p->dataField->dataFieldHeader->setFieldValue(10, 250); // ADDNUMBER + p->dataField->dataFieldHeader->setFieldValue(11, 10); // PACKETNUM + p->dataField->dataFieldHeader->setFieldValue(12, 8); // PACKETCOUN + p->dataField->dataFieldHeader->setFieldValue(14, 8); // PIXELNUMBER + + SDFBlockFixed* sdf = (SDFBlockFixed*) p->dataField->sourceDataField; + for (int i=0; i<268; i++) { + // get a block of the source data field + SDFBFBlock* block = sdf->getBlock(i); + block->setFieldValue_3_13(0, 1456121); // PIXELVALUE + block->setFieldValue(4, 16); + } + + ops.writePacket(p); + + cout << "PACKET: " << p->getName() << endl; + cout << "Size: " << p->getDimension() << endl; + cout << "APID: " << p->header->getFieldValue(3) << endl; + cout << "Data Length: " << p->header->getFieldValue(6) << endl; + cout << "HexStream: " << p->packet_output->printStreamInHexadecimal() << endl; + + // Deallocate memory used by the packet + p->deleteExternalByteStream(); + + //close output + out->close(); + + readpacket(filename); + } + catch(PacketException* e) { + cout << "ERROR-" << e->geterrorcode() << ": " << e->geterror() << endl; + } +} + +int main2() { +try { + Output* out; + OutputPacketStream ops; + char* filename = "bugs/tail/p3914.stream"; + //create the structure + ops.setFileNameConfig(filename); + ops.createStreamStructure(); + + //parameter for output: file + out = (Output*) new OutputFile(ops.isBigEndian()); + char** param = (char**) new char* [2]; + param[0] = "./test.raw"; //nome file + param[1] = 0; + + //open the output + out->open(param); + + ops.setOutput(out); + + //send a TM packet + Packet* p = ops.getPacketType(1); + + // Number of blocks is fixed + //p->dataField->sourceDataField->setNumberOfRealDataBlock(268); + p->header->setFieldValue(3, 767); + + // set data fields + p->dataField->dataFieldHeader->setFieldValue(3, 39); + p->dataField->dataFieldHeader->setFieldValue(4, 14); + int nb = 1; + p->dataField->setNumberOfRealDataBlock(nb); + + SDFBlockFixed* sdf = (SDFBlockFixed*) p->dataField->sourceDataField; + for (int i=0; igetBlock(i); + int nf = sdf->getNumberOfFields(); + for(int j=0; jsetFieldValue(j, j); // PIXELVALUE + } + + + p->dataField->tail->setFieldValue(0, 876); + ops.writePacket(p); + cout << "PACKET: " << p->getName() << endl; + cout << "Size: " << p->getDimension() << endl; + cout << "Packet length: " << p->header->getFieldValue(6) << endl; + //cout << "Data Length: " << p->header->getFieldValue(6) << endl; + //cout << "HexStream: " << p->packet_output->printStreamInHexadecimal() << endl; + cout << "Tail: " << p->dataField->tail->getFieldValue(0) << endl; + cout << p->printPacketOutputStream() << endl; + char** cc = (char**)p->dataField->sourceDataField->printValue(); + int num=0; + while(cc[num] != 0) { + cout << cc[num] << endl; + num++; + } + // Deallocate memory used by the packet + p->deleteExternalByteStream(); + + //close output + out->close(); + + readpacket(filename); + + +} catch (PacketException* e) { + cout << e->geterror() << endl; +} +} + +void extractFields(Packet* p) +{ +SourceDataField* sdf = p->dataField->sourceDataField; +int apid; + cout << "APID: " << (apid = p->header->getFieldValue(3)) << endl; + cout << "Total dimension: " << p->getDimension() << endl; + cout << "Packet Length: " << p->header->getFieldValue(6) << endl; + Field* field = p->header->getFields(3); + cout << "field name " << field->name << endl; + cout << "field dimension " << field->dimension << endl; + cout << "field value " << field->value << endl; + cout << "number of blocks. " << p->dataField->getNumberOfRealDataBlock() << endl; + // cout << "Number Of Week: " << p->dataField->dataFieldHeader->getFieldValue(3) << endl; + // cout << "Seconds In Week: " << p->dataField->dataFieldHeader->getFieldValue_4_14(4) << endl; + // cout << "Internal Timer Value: " << p->dataField->dataFieldHeader->getFieldValue(6) << endl; + // cout << "Counter 1/32 Hz: " << p->dataField->dataFieldHeader->getFieldValue(7) << endl; + // cout << "Counter 1 Hz: " << p->dataField->dataFieldHeader->getFieldValue(8) << endl; +// char** cc = p->dataField->sourceDataField->printValue(); +// int num=0; +// while(cc[num] != 0) { +// cout << cc[num] << endl; +// num++; +// } + + switch (apid) { + case 1103: + cout << "ASTBKGROUNDID: " << p->dataField->dataFieldHeader->getFieldValue(9) << endl; + for (int i=0; i<32; i++) { + cout << "SUPIXELERR[" << i << "]: " << sdf->getFieldValue( i, 0) << endl; + cout << "MEANSKYSP[" << i << "]: " << sdf->getFieldValue_3_13( i, 1) << endl; + cout << "VARSKYSP[" << i << "]: " << sdf->getFieldValue( i, 3) << endl; + cout << "MEANSKYBP[" << i << "]: " << sdf->getFieldValue_3_13( i, 4) << endl; + // Work around to fix the problem + //cout << "MEANSKYSP[" << i << "]: " << ((long(sdf->getFieldValue( i, 1)) * 256) + long(sdf->getFieldValue( i, 2)) ) << endl; + //cout << "MEANSKYBP[" << i << "]: " << ((long(sdf->getFieldValue( i, 4)) * 256) + long(sdf->getFieldValue( i, 5)) ) << endl; + } + break; + case 1113: + cout << "DIM " << sdf->getFields(0, 3)->dimension << endl; + cout << "PROVA2 " << sdf->getFieldValue(0, 4) << endl; + cout << "PIXELVALUE " << sdf->getFieldValue_3_13( 0, 0) << endl;; + break; + case 767: + cout << "TAIL " << p->dataField->tail->getFieldValue(0) << endl; + cout << p->printSourceDataFieldStream() << endl; + cout << p->dataField->sourceDataField->getDimension() << endl; + default: break; + } +} + + +int readpacket(char* filename) { +Input* in; + try { + InputPacketStreamFile* ips = new InputPacketStreamFile(); + ByteStream* bs; + bool endcycle = false; + + //create the structure + ips->setFileNameConfig(filename); + ips->createStreamStructure(); + + ips->setFileNameStream("./test.raw"); + ips->setInitialPosition(0); + ips->openInputStream(); + ips->freeRun(); + + cout << ips->packetLibVersion() << endl; + + cout << "INPUT: FILE" << endl; + + int numberPackets = ips->getNumberOfFileStreamPointer(); + cout << " Number packets = " << numberPackets << endl; + + for(int index=0; indexgetPacketFromFileStreamPointer(index); + if (p == NULL) { + cout << "Packet not recognized." << endl; + } + else { + cout << "PACKET: " << p->getName() << endl; + cout << "Size: " << p->getDimension() << endl; + int apid = p->header->getFieldValue(3); + extractFields(p); + } + // Deallocate memory used by the packet + if(p) p->deleteExternalByteStream(); + } + + /* + in = (Input*) new InputFile(ips.isBigEndian()); + cout << "INPUT: FILE" << endl; + char** param = (char**) new (char*)[2]; + param[0] = "test.raw"; + param[1] = 0; + + //open input + in->open(param); + + ips.setInput(in); + + //crea l'input + int i = 0; + while (! in->isEOF()) { + Packet* p = ips.readPacket(); + if( in->isEOF()) + break; + if(p->getPacketID() == 2) { + cout << i++ << " INPUT: " << p->getName() << " - number of blocks: " << p->dataField->sourceDataField->getNumberOfRealDataBlock() << endl; + cout << p->dataField->dataFieldHeader->getFieldValue_3_13(4) << endl; + cout << p->dataField->sourceDataField->getFieldValue_4_14(1, 0) << endl; + + SDFBlockFixed* sdf = (SDFBlockFixed*) p->dataField->sourceDataField; + SDFBFBlock* block = sdf->getBlock(0); + cout << block->getFieldValue_5_1(0) << endl; + + //print the list of values + char **c = p->dataField->sourceDataField->printValue(); + int i = 0; + while(c[i]) + cout << c[i++] << endl; + } + //when you have finished to use the packet, it is important to + //deallocate the memory allocated during the reading operation from input + p->deleteExternalByteStream(); + } + + in->close(); + return 0; +*/ + //ByteStream *b = new ByteStream(10, false); + /*Utility u; + char* filenameConfig = "/home/bulgarelli/Projects/AGILE_TM_Generator/conf/AGILE_TM_GENERATOR.stream"; + char* filenameOutput = "/home/bulgarelli/3901.raw"; + Device d(true); + Output* out; + OutputPacketStream ops; + SDFRBlock* sdf; + SDFRBBlock* b0; + SDFRBBlock* bcX, *TAA1, *mcal; + char** param; + cout << *Utility::wordToBinary((word)150, 6) << endl; + cout << Utility::integerToString3("str%d", 3) << endl; + + + InputPacketStream ips(filenameConfig); + ips.createStreamStructure(); + Packet* p = ips.getPacketType(1); + cout << "MAX DIMENSION " << p->getMaxDimension() << endl; + + sdf = (SDFRBlock*) p->dataField->sourceDataField; + //the number of grid blocks + sdf->setNumberOfRealDataBlock(1, 0); + + cout << "SDF nfields " << sdf->getNumberOfFields() << endl; + + b0 = sdf->getBlock(0, 0); + + b0->setNumberOfRealDataBlock(1, 0); + b0->setNumberOfRealDataBlock(1, 1); + b0->setNumberOfRealDataBlock(1, 2); + b0->setNumberOfRealDataBlock(3, 3); + + cout << "Number of read data block of SDF: " << p->dataField->sourceDataField->getNumberOfRealDataBlock(0) << endl; + + cout << "Real Dimension of Packet: " << p->getDimension() << endl; + + //goto READP; + //************************************************************** + // Generate a tm grid packet + //************************************************************** + //crea la struttura dei telemetry packet in memoria + ops.setFileNameConfig(filenameConfig); + ops.createStreamStructure(); + + //parametri per output: file + out = (Output*) new OutputFile(ops.isBigEndian()); + param = (char**) new (char*)[2]; + param[0] = filenameOutput; //nome file + param[1] = 0; + + //apri l'output + out->open(param); + + //setta l'output specifico + ops.setOutput(out); + + //invia un packet + p = ops.getPacketType(1); + p->header->setFieldValue(3, 1294); + p->dataField->dataFieldHeader->setFieldValue(3, 39); + p->dataField->dataFieldHeader->setFieldValue(4, 1); + p->dataField->tail->setFieldValue(0, 11); + + //SI SETTANO ALCUNI VALORI + sdf = (SDFRBlock*) p->dataField->sourceDataField; + sdf->setNumberOfRealDataBlock(1, 0); //1 block for rtype 0 + b0 = sdf->getBlock(0, 0); //get the block 0 of rblock 0 + b0->setNumberOfRealDataBlock(1, 0); + b0->setNumberOfRealDataBlock(1, 1); + b0->setNumberOfRealDataBlock(1, 2); + b0->setNumberOfRealDataBlock(3, 3); + sdf->setFieldValue(0, 1); //set into the fixed part of SDF + sdf->setFieldValue(1, 2); + + //get the cluster X block 0 + bcX = b0->getBlock(0, 0); + bcX->setFieldValue(0, 2); + TAA1 = b0->getBlock(2, 3); + TAA1->setFieldValue(2, 1); + mcal = b0->getBlock(0, 2); + mcal->setFieldValue(1, 7); + + cout << "VERIFY: " << sdf->getFieldValue(0) << endl; + cout << "Real Dimension of Packet to be written " << p->getDimension() << endl; + cout << "Total number of fields " << sdf->getNumberOfFields() << endl; + ops.writePacket(p); + //cout << p->packet_output->printStreamInHexadecimal() << endl; + cout << p->packet_output->getDimension()<< endl; + //chiudi l'output + out->close(); + + READP: + //************************************************************** + // Reopen and recognize the tm packet + //************************************************************** + Input* in; + //parametri per input: file + in = (Input*) new InputFile(ips.isBigEndian()); + param = (char**) new (char*)[2]; + param[0] = filenameOutput; + param[1] = 0; + + //apri l'input + in->open(param); + + //setta il particolare tipo di input + ips.setInput(in); + + p = ips.readPacket(); + cout << "Packet name: " << p->getName() << endl; + cout << p->dataField->sourceDataField->stream->printStreamInHexadecimal() << endl; + cout << "READED: " << p->dataField->sourceDataField->getFieldValue(0) << endl; + sdf = (SDFRBlock*) p->dataField->sourceDataField; + cout << "Readed: number of block of SDF " << sdf->getNumberOfRealDataBlock() << endl; + cout << "Readed: number of block of SDF " << sdf->getFieldValue(14) << endl; + b0 = sdf->getBlock(0, 0); + bcX = b0->getBlock(0, 0); + mcal = b0->getBlock(0, 2); + TAA1 = b0->getBlock(2, 3); + cout << "Readed cluster X block 0 block 0 field 0: " << bcX->getFieldValue(0) << endl; + cout << mcal->getFieldValue(1) << endl; + cout << TAA1->getFieldValue(2) << endl; + cout << TAA1->fixed.stream->printStreamInHexadecimal() << endl; + + cout << "CHECKSUM: " << p->dataField->tail->getFieldValue(0) << endl; + + p->printPacketValue(); + //chiudi l'input + in->close(); + + + //********************************************* + + cout << " ----------------------- input packet stream file -------------" << endl; + InputPacketStreamFile* ipsf = new InputPacketStreamFile() ; + ipsf->setFileNameConfig(filenameConfig); + ipsf->createStreamStructure(); + ipsf->setFileNameStream(filenameOutput); + ipsf->setInitialPosition(0); + ipsf->openInputStream(); + ipsf->freeRun(); + + // p->printPacketValue(); + + word num = ipsf->getNumberOfPacketType(); + int stat[num]; + for(int i=0; i::iterator it; + for(it=ipsf->listOfFileStreamPointer.begin();it!=ipsf->listOfFileStreamPointer.end(); it++) { + cout << it->nameOfPacket << " - " << it->index << endl; + stat[it->typeOfPacket]++; + } + + for(int i=0; igetPacketType(i); + cout << p->getName() << ":" << stat[i] << endl; + } + + p = ipsf->getPacketFromFileStreamPointer(0); + if(p == NULL) + cout << "NULL NULL !!!!!!!!!!!!!!!" << endl; + + cout << "Packet name: " << p->getName() << endl; + cout << "CHECKSUM: " << p->dataField->tail->getFieldValue(0) << endl; + cout << "END" << endl; + return 1;*/ +} catch (PacketException* e) { + cout << e->geterror() << endl; + +} +} diff --git a/examples/examples2/msgqclient.cpp b/examples/examples2/msgqclient.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f4aba2d67dc3e964bda5f7e227db52d291f5225b --- /dev/null +++ b/examples/examples2/msgqclient.cpp @@ -0,0 +1,54 @@ +/*************************************************************************** + main.cpp - description + ------------------- + begin : Thu Dec 5 08:23:25 CET 2002 + copyright : (C) 2002 by Andrea Bulgarelli + email : bulgarelli@bo.iasf.cnr.it + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include "MSGQ.h" +#include "PacketException.h" + +using namespace PacketLib; + +#define SENDER_MSGQ_LEN 255 +#define SENDER_MSG_TYPE 10 + + +int main(int argc, char *argv[]) +{ + try { + char* mtext = new char[SENDER_MSGQ_LEN]; + + MSGQ msgq(true); //creo l'oggetto + + msgq.open(10000, SENDER_MSGQ_LEN); //apro la message queue + + //setto i valori da scrivere + for(int i = 0; i < SENDER_MSGQ_LEN; i++) + mtext[i] = 35; + + //scrivo il packet + msgq.writeMessage(mtext, (long)SENDER_MSG_TYPE); + + cout << "End of the program" << endl; + } + catch(PacketException* e) { + cout << e->geterror() << endl; + } +} diff --git a/examples/examples2/msgqserver.cpp b/examples/examples2/msgqserver.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6e4124b7a66adb3ea6d6882c07a9c50fe17cb08b --- /dev/null +++ b/examples/examples2/msgqserver.cpp @@ -0,0 +1,53 @@ +/*************************************************************************** + main.cpp - description + ------------------- + begin : Thu Dec 5 08:00:28 CET 2002 + copyright : (C) 2002 by Andrea Bulgarelli + email : bulgarelli@bo.iasf.cnr.it + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include "MSGQ.h" +#include "PacketException.h" + +using namespace PacketLib; + +#define SENDER_MSGQ_LEN 255 +#define SENDER_MSG_TYPE 10 + +int main(int argc, char *argv[]) +{ + try { + char* buf; + + MSGQ msgq(true); + msgq.create(10000, SENDER_MSGQ_LEN); + cout << "Wait for a message..." << endl; + + buf = msgq.readMessage(SENDER_MSG_TYPE); + + for(int i=0; i< SENDER_MSGQ_LEN; i++) + cout << buf[i]; + + msgq.destroy(); + cout << "End of the program" << endl; + } + catch(PacketException* e) { + cout << e->geterror() << endl; + } + +} diff --git a/examples/examples2/socketin.cpp b/examples/examples2/socketin.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e38714877d9487546fc0eaa7bf18625daf7742d3 --- /dev/null +++ b/examples/examples2/socketin.cpp @@ -0,0 +1,93 @@ +/*************************************************************************** + main.cpp - description + ------------------- + begin : Sat Oct 26 15:30:53 CEST 2004 + copyright : (C) 2002 by Andrea Bulgarelli + email : bulgarelli@bo.iasf.cnr.it + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include "InputSocketServer.h" +#include "InputPacketStream.h" +#include "Input.h" +#include "InputFile.h" +#include "Packet.h" + +using namespace PacketLib; + +int main(int argc, char *argv[]) +{ + try { + Input* in; + + InputPacketStream ips; + ByteStream* bs; + bool endcycle = false; + + //create the structure + ips.setFileNameConfig("config_files/BURST.stream"); + ips.createStreamStructure(); + + //crea l'input + + //parameter for input: socket server + in = (Input*) new InputSocketServer(ips.isBigEndian()); + cout << "INPUT: SOCKET SERVER 20000" << endl; + char** param = (char**) new (char*)[2]; + param[0] = "20000"; //porta + param[1] = 0; + + //parameter for input: file + /*in = (Input*) new InputFile(ips.isBigEndian()); + cout << "INPUT: FILE" << endl; + char** param = (char**) new (char*)[2]; + param[0] = "../../test.raw"; + param[1] = 0; + */ + + //open input + in->open(param); + + ips.setInput(in); + + //read a byte stream from input + /*while(!endcycle) { + cout << "Attendo dati..." << endl; + bs = in->readByteStream(10); + if (bs != 0) { + cout << bs->printStreamInHexadecimal() << endl; + cout << "------------------------" << endl; + } + else { + if(in->isEOF()) + endcycle = true; + } + } */ + + Packet* p = ips.readPacket(); + cout << "INPUT: " << p->getName() << endl; + cout << "INPUT: " << p->header->stream->printStreamInHexadecimal() << endl; + + //close input + in->close(); + + } + catch(PacketException* e) { + cout << e->geterror() << endl; + } + +} diff --git a/examples/examples2/socketout.cpp b/examples/examples2/socketout.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d6e0f486a6da71a5d0b5eeae9195c690196f62d6 --- /dev/null +++ b/examples/examples2/socketout.cpp @@ -0,0 +1,86 @@ +/*************************************************************************** + main.cpp - description + ------------------- + begin : Sat Oct 26 15:31:22 CEST 2004 + copyright : (C) 2002 by Andrea Bulgarelli + email : bulgarelli@bo.iasf.cnr.it + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include "OutputSocketClient.h" +#include "OutputPacketStream.h" +#include "ByteStream.h" +#include "Output.h" +#include "OutputFile.h" + +using namespace PacketLib; + +int main(int argc, char *argv[]) +{ + try { + Output* out; + OutputPacketStream ops; + + //create the structure + ops.setFileNameConfig("config_files/BURST.stream"); + ops.createStreamStructure(); + + //parameter for output: socket client + out = (Output*) new OutputSocketClient(ops.isBigEndian()); + cout << "OUTPUT: SOCKET CLIENT 20000" << endl; + char** param = (char**) new (char*)[3]; + param[0] = "localhost"; //host + param[1] = "20000"; //porta + param[2] = 0; + + //parameter for output: file + /*out = (Output*) new OutputFile(ops.isBigEndian()); + char** param = (char**) new (char*)[2]; + param[0] = "../../test.raw"; //nome file + param[1] = 0;*/ + + //open the output + out->open(param); + + ops.setOutput(out); + + //send a byte stream + /*ByteStream* bl = new ByteStream(10, ops.isBigEndian()); + for(int i=0; i< 10; i++) + bl->setByte(i, i); + + out->writeByteStream(bl); + out->writeByteStream(bl); + */ + + + //send a TC packet + Packet* p = ops.getPacketType(2); + p->header->setFieldValue(3, 257); + p->header->setFieldValue(5, 1); + cout << "OUTPUT: "; + + ops.writePacket(p); + cout << p->packet_output->printStreamInHexadecimal() << endl; + + //close output + out->close(); + } + catch(PacketException* e) { + cout << e->geterror() << endl; + } +}