diff --git a/include/InputPacketStream.h b/include/InputPacketStream.h index 38a2548a5afab81e0e20888c315aaf0cc28554cf..4109881edae8bb2a3ab7576542be461182055407 100644 --- a/include/InputPacketStream.h +++ b/include/InputPacketStream.h @@ -62,8 +62,9 @@ public: /// This method read a telemetry packet /// \pre The setInput method must be invocated + /// \param bDecode if true decode the method will decode the data fields. /// \return A pointer telemetry packet. Make attention: the object returned is one of the TM packet object of the array of this object. Don't delete it! - Packet* readPacket() throw(PacketExceptionIO*); + Packet* readPacket(bool bDecode = true) throw(PacketExceptionIO*); Packet* decodePacket(ByteStreamPtr stream); diff --git a/include/Packet.h b/include/Packet.h index 10808fbdf575e4d0c5591230e90c2c9c3a2b95aa..334c0e80a763216acee52dfcf47e775e9eeaf95a 100644 --- a/include/Packet.h +++ b/include/Packet.h @@ -64,6 +64,9 @@ public: /// correct value virtual bool setAndVerifyPacketValue(ByteStreamPtr prefix, ByteStreamPtr packet); + /// Set the internal prefix and packet. Decode only the header. + virtual void setByteStreamPointers(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField); + /// Sets all the fields of the packet with correct value contained into the input ByteStream. /// \pre The structure of the stream must be loaded. /// \param prefix This is the prefix of the packet diff --git a/include/SourceDataField.h b/include/SourceDataField.h index 932350215bd84d800647474ee5192dd7c581ba1d..1d224ba091680ee021eb6109f387fb497d7c602c 100644 --- a/include/SourceDataField.h +++ b/include/SourceDataField.h @@ -34,7 +34,7 @@ public: virtual ~SourceDataField(); /// Sets the stream of byte. This method assigns the value of stream for each field of part of packet - virtual bool setByteStream(ByteStreamPtr s, bool onlySections = false) { PartOfPacket::setByteStream(s); }; + virtual bool setByteStream(ByteStreamPtr s, bool onlySections = false) { PartOfPacket::setByteStream(s); return true; }; /// Gets the total max dimension in bytes of source data field virtual dword getMaxDimension() = 0; diff --git a/src/ByteStream.cpp b/src/ByteStream.cpp index f91cb332035ce0c429741e164678908e00422ec3..f7addebbff772b9c05750d95271d51d45837181e 100644 --- a/src/ByteStream.cpp +++ b/src/ByteStream.cpp @@ -97,7 +97,6 @@ PacketLib::ByteStream::ByteStream(ByteStreamPtr b0, ByteStreamPtr b1, ByteStream mem_allocation_constructor = true; /// Streams are swapped - dword i = 0; dword dim = 0; if(b0 == 0 && b1 == 0 && b2 == 0) { @@ -112,35 +111,22 @@ PacketLib::ByteStream::ByteStream(ByteStreamPtr b0, ByteStreamPtr b1, ByteStream byteInTheStream = (b0!=0?b0->getDimension():0) + (b1!=0?b1->getDimension():0) + (b2!=0?b2->getDimension():0); stream = (byte*) new byte[byteInTheStream]; this->bigendian = (b0!=0?b0->isBigendian():(b1!=0?b1->isBigendian():(b2!=0?b2->isBigendian():false))); - - //TODO AZ: fare il memcpy - - if(b0 != 0) - { - dim = b0->getDimension(); - for(; igetDimension(); i++) - stream[i] = b0->stream[i]; - } - if(b1!=0) - { - dim += b1->getDimension(); - dword istart = i; - for(; istream[pos]; - } - } - if(b2!=0) - { - dim += b2->getDimension(); - dword istart = i; - for(; istream[pos]; - } - } + + if(b0 != 0) + { + memcpy(stream, b0->stream, b0->getDimension()); + dim += b0->getDimension(); + } + if(b1 != 0) + { + memcpy(stream+dim, b1->stream, b1->getDimension()); + dim += b1->getDimension(); + } + if(b2 != 0) + { + memcpy(stream+dim, b2->stream, b2->getDimension()); + dim += b2->getDimension(); + } setMemoryAllocated(true); mem_allocation_constructor = false; } diff --git a/src/File.cpp b/src/File.cpp index 96045dcabe0edc523802d8b77d76d1c3a44db7e9..3e896cdc2cf382d480f73674c37dd5e1a2422e40 100644 --- a/src/File.cpp +++ b/src/File.cpp @@ -108,49 +108,16 @@ int File::getByte() ByteStreamPtr File::getNByte(dword N) { - dword i = 0; - int c1, c2; - if(N == 0) - return ByteStreamPtr(new ByteStream(0, bigendian)); - //solo un numero pari di byte - //if(N%2 != 0 || !fileOpened) return NULL; - - if(closed) return NULL; + if(N == 0) + return ByteStreamPtr(new ByteStream(0, bigendian)); - //ByteStreamPtr b = new ByteStream(N, bigendian); byte* stream = (byte*) new byte[N]; + size_t result = fread(stream, 1, N, fp); + byte_read += result; + if(result != N) + eof = true; - for(i = 0; istream[i] = c1; - b->stream[i+1] = c2; - } - else //little endian - { - //se la macchina lavora in little endian, per "far tornare i conti" e' necessario - //invertire i byte letti - b->stream[i] = c2; - b->stream[i+1] = c1; - }*/ - } - /*if(i != N) - { - ByteStreamPtr b1 = new ByteStream(i, bigendian); - for(int j = 0; jstream[j] = b->stream[j]; - delete b; - b = b1; - } */ - //for(; istream[i] = 0; - //return b; - return ByteStreamPtr(new ByteStream(stream, i, bigendian, false)); + return ByteStreamPtr(new ByteStream(stream, result, bigendian, false)); } diff --git a/src/InputPacketStream.cpp b/src/InputPacketStream.cpp index bd3a84b21953f70aee8a666df60e4ab45d3ab93d..55d7e2ff37c3a43f229bfcac0dabba4f6f2312bd 100644 --- a/src/InputPacketStream.cpp +++ b/src/InputPacketStream.cpp @@ -89,7 +89,7 @@ void InputPacketStream::setInput(Input* in) -Packet* InputPacketStream::readPacket() throw(PacketExceptionIO*) +Packet* InputPacketStream::readPacket(bool bDecode) throw(PacketExceptionIO*) { unsigned dimHeader = getHeaderDimension(); unsigned dimPrefix = getPrefixDimension(); @@ -145,11 +145,20 @@ Packet* InputPacketStream::readPacket() throw(PacketExceptionIO*) else pindex = detPacketType(b0, b1, b2); } - Packet* p = packetType[pindex]; - //TODO - if(!p->setPacketValue(b0, b1, b2)) //gli stream diventano del packet - throw new PacketExceptionIO("it is impossible to resolve the packet."); - return p; + + Packet* p = packetType[pindex]; + + if(bDecode) + { + if(!p->setPacketValue(b0, b1, b2)) //gli stream diventano del packet + throw new PacketExceptionIO("it is impossible to resolve the packet."); + } + else + { + p->setByteStreamPointers(b0, b1, b2); + } + return p; + } catch(PacketExceptionIO* e) { diff --git a/src/Packet.cpp b/src/Packet.cpp index bff385a010f5ccb6ce5a47501ee05612900cb932..2fe76571f83dfaa5cfbe15634d75bca928a47cad 100644 --- a/src/Packet.cpp +++ b/src/Packet.cpp @@ -292,13 +292,18 @@ void Packet::printIdentifiers() } } - -bool Packet::setPacketValue(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField, bool onlySections) +void Packet::setByteStreamPointers(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField) { - //cout << "@ " << packetDataField->getDimension() << endl; memByteStream(prefix, packetHeader, packetDataField); ByteStreamPtr packet = ByteStreamPtr(new ByteStream(packetHeader, packetDataField, 0)); memByteStream(prefix, packet); +} + +bool Packet::setPacketValue(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField, bool onlySections) +{ + setByteStreamPointers(prefix, packetHeader, packetDataField); + + //cout << "@ " << packetDataField->getDimension() << endl; /// 1) if(!setPacketValueVerify(prefix, packetHeader, packetDataField)) { @@ -397,7 +402,7 @@ bool Packet::verifyPacketValue(ByteStreamPtr prefix, ByteStreamPtr packetHeader, for(unsigned i = 0; i< number_of_identifier; i++) { PacketIdentifier* pi = identifiers[i]; - Field* f; + Field* f = NULL; switch(pi->type) { case 0: @@ -411,7 +416,7 @@ bool Packet::verifyPacketValue(ByteStreamPtr prefix, ByteStreamPtr packetHeader, f = dataField->sourceDataField->getFields(pi->fieldNumber); break; } - if(f->value != pi->value) + if(f == NULL || f->value != pi->value) { verified = false; break; diff --git a/src/PartOfPacket.cpp b/src/PartOfPacket.cpp index e97d4a67a9eb17f9cb1f9eb081f866f79f611d25..1949fb4e5a0fb20ac28230691fd6fa7d4d6edf7b 100644 --- a/src/PartOfPacket.cpp +++ b/src/PartOfPacket.cpp @@ -51,7 +51,7 @@ PartOfPacket::~PartOfPacket() string* PartOfPacket::printStructure() { bool first = true; - char *s; + char *s = NULL; for(unsigned i=0; i< numberOfFields; i++) { @@ -280,7 +280,7 @@ bool PartOfPacket::decode() { /* cout << i << ": " << ftemp->value << endl; cout << i << ": " << (ftemp->value << currentDimBit) << endl; cout << i << ": " << wordtemp << endl;*/ - ftemp->value = (ftemp->value) | wordtemp & pattern[dimbit]; + ftemp->value = ftemp->value | (wordtemp & pattern[dimbit]); /* cout << i << ": " << ftemp->value << endl; cout << i << ": " << (wordtemp & pattern[dimbit]) << endl;*/ } diff --git a/src/SDFBlockFixed.cpp b/src/SDFBlockFixed.cpp index 02c0462c849a4ae66b436e665a5a524c48d6bce3..8c691aff804d9fc9ca54867a0090a7441683f8ac 100644 --- a/src/SDFBlockFixed.cpp +++ b/src/SDFBlockFixed.cpp @@ -264,12 +264,12 @@ dword SDFBlockFixed::getDimension(word nblock) dword SDFBlockFixed::getMaxDimension() { /// Event dimension - dword dimOfEventBlock; + dword dimOfEventBlock = 0; if(block != NULL) dimOfEventBlock = block[0].getDimension(); else { - ; //TODO lanciare una eccezione + throw PacketException("Error on SDFBlockFixed::getMaxDimension: block is NULL"); } return dimOfEventBlock * maxNumberOfBlock[0]; } diff --git a/src/SDFBlockVariable.cpp b/src/SDFBlockVariable.cpp index b166fc242e3a05b7e601b33aa131c10de033a0db..b4e7cdd9b8da7981c139add0e20d7ea0e2f0eb9e 100644 --- a/src/SDFBlockVariable.cpp +++ b/src/SDFBlockVariable.cpp @@ -29,12 +29,12 @@ bool SDFBlockVariable::loadFields(InputText& fp) throw(PacketException*) { try { - char* line, *linesection; + char* line, *linesection = NULL; word indexOfNElement; unsigned addToNElements; word maxNumberOfElement; bool first1 = true, first2 = true; - MemoryBuffer* buffer1, *buffer2; + MemoryBuffer* buffer1, *buffer2 = NULL; line = fp.getLine(); if(strcmp(line, "fixed") == 0)