From a3bbbd408a8d870f5ee19b27b253ba748c028596 Mon Sep 17 00:00:00 2001 From: Andrea Bulgarelli Date: Wed, 18 Sep 2013 10:40:36 +0200 Subject: [PATCH] bool Packet::createPacketType() bug fix --- ChangeLog | 4 ++++ include/InputPacketStream.h | 2 ++ include/Packet.h | 4 ++++ src/InputPacketStream.cpp | 13 +++++++++++++ src/Packet.cpp | 23 +++++++++++++++++++++-- 5 files changed, 44 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 598eee7..ff76b3a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2013-09-18 bulgarelli Andrea Bulgarelli + + * src/Packet.cpp (Packet::createPacketType): bool Packet::createPacketType(char* fileName, bool isprefix, word dimprefix) bug fix when the configuration files are read more than one time + 2013-09-17 Andrea Bulgarelli * include/InputPacketStream.h (InputPacketStream): diff --git a/include/InputPacketStream.h b/include/InputPacketStream.h index 9e1dc32..de3f744 100644 --- a/include/InputPacketStream.h +++ b/include/InputPacketStream.h @@ -65,6 +65,8 @@ public: /// \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* decodePacket(byte* stream); + protected: Input* in; diff --git a/include/Packet.h b/include/Packet.h index e2b865c..0cd9785 100644 --- a/include/Packet.h +++ b/include/Packet.h @@ -90,6 +90,10 @@ public: /// \param stream A pointer to the stream of byte, with prefix and packet bool verifyPacketValue(byte* stream); + /// Sets all the fields of the packet with correct value contained into the input ByteStream. + /// \param stream A pointer to the stream of byte, with prefix and packet + bool setPacketValue(byte* stream); + /// Verifies if within the ByteStream passed with arguments it's present a correct packet. /// \pre The structure of the stream must be loaded. /// \param prefix This is the prefix of the packet. diff --git a/src/InputPacketStream.cpp b/src/InputPacketStream.cpp index db886e5..a58055a 100644 --- a/src/InputPacketStream.cpp +++ b/src/InputPacketStream.cpp @@ -174,3 +174,16 @@ dword InputPacketStream::getPacketDimension(byte* stream) { delete tempHeader; return dim; } + +Packet* PacketLib::InputPacketStream::decodePacket(byte* stream) { + + int index = detPacketType(stream); + if(index > 0) { + Packet* p = getPacketType(index); + p->setPacketValue(stream); + return p; + } + else + return 0; + +} diff --git a/src/Packet.cpp b/src/Packet.cpp index 33542ca..16652eb 100644 --- a/src/Packet.cpp +++ b/src/Packet.cpp @@ -93,6 +93,7 @@ bool Packet::createPacketType(char* fileName, bool isprefix, word dimprefix) thr if(file.open(argv)) { delete[] argv; + file.setpos(0); /// retrieve name of packet header name = file.getLine(); /// find the PacketHeader section @@ -158,8 +159,8 @@ bool Packet::createPacketType(char* fileName, bool isprefix, word dimprefix) thr if(!section_found) throw new PacketExceptionFileFormat("It's impossibile to identify the type of source data field. Expected block, noblock or rblock keyword."); - delete[] block; - delete[] typeOfPacket; + //delete[] block; + //delete[] typeOfPacket; if(dataField->sourceDataField->loadFields(file)) { @@ -854,3 +855,21 @@ bool Packet::verifyPacketValue(byte* stream) { return verifyPacketValue(prefix, packet); } + +bool Packet::setPacketValue(byte* stream) { + dword dimPre = 0; + if(thereisprefix) + dimPre += dimPrefix; + ByteStream* prefix = new ByteStream(stream, dimPre, bigendian); + + dword dim = 0; + dword dimHeader = header->getDimension(); + dim += dimHeader; + tempHeader->setStream(stream+dimPre, dimHeader, bigendian); + header->setByteStream(tempHeader); + dim += header->getDimensionOfPacketLenght() + 1; + ByteStream* packet = new ByteStream(stream+dimPre, dim, bigendian); + + return setPacketValue(prefix, packet); + +} -- GitLab