Skip to content
Snippets Groups Projects
Commit 7751cc69 authored by Andrea Bulgarelli's avatar Andrea Bulgarelli
Browse files

+ size() instead of getDimension

+ sizeMax()
+ removed decodeTupe
+ Packet::verify()
+ Packet::set()
parent 95349f53
No related branches found
No related tags found
No related merge requests found
Showing with 290 additions and 312 deletions
2014-03-09 Andrea Bulgarelli <bulgarelli@iasfbo.inaf.it>
+ size() instead of getDimension
+ sizeMax()
+ removed decodeTupe
+ Packet::verify()
+ Packet::set()
2014-03-09 Andrea Bulgarelli <bulgarelli@iasfbo.inaf.it>
TAG v4.0.0
+ moved InputPacketStream::getPacket() to PacketStream
......
......@@ -100,7 +100,7 @@ public:
long getValue(dword start, word dim);
/// Gets the dimension of the stream
dword getDimension();
dword size();
char* printStreamInHexadecimal();
......
......@@ -59,7 +59,7 @@ public:
word value;
/// Dimension of field in bit.
inline dword getDimension()
inline dword size()
{
return type->dimension;
};
......
......@@ -44,7 +44,7 @@ public:
/// \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(int decodeType = 2) throw(PacketExceptionIO*);
Packet* readPacket() throw(PacketExceptionIO*);
......
......@@ -30,6 +30,15 @@
#include "PacketExceptionIO.h"
#include "PacketExceptionFileFormat.h"
//Packet::size()
//stream = prefix + packet
//Packet::set(ByteStreamPtr stream)
//Packet::set(ByteStreamPtr prefix, ByteStream packet)
//Packet::set(ByteStreamPtr prefix, ByteStreamPtr header, ByteStreamPtr dataField)
//check if the stream
//bool Packet::verify()
//char** Packet::printFields()
//char* Packet::printStream();
namespace PacketLib
{
......@@ -47,59 +56,27 @@ public:
virtual bool createPacketType(char* fileName, bool prefix, word dimprefix) throw (PacketException*);
/// This method verifies if the ByteStream on argument contains the correct value
/// in the identifiers. If this is true, the method return true and the stream
/// contains a packet of this type. This method overloads another method.
/// \post the bytestream is decoded
virtual bool setAndVerifyPacketValue(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField);
/// This method verifies if the ByteStream on argument contains the correct value
/// in the identifiers. If this is true, the method returns true and the stream
/// contains a packet of this type. This method overloads another method.
/// \post the bytestream is decoded
virtual bool setAndVerifyPacketValue(ByteStreamPtr prefix, ByteStreamPtr packet);
/// 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
/// \param packetHeader This is the header of the packet
/// \param packetDataField This is the data field of the packet
/// \param decodeType (0) do not decode anything (1) decode only sections (prefix, header, data field header, source data field fixed part, source data field variable part) (2) decode blocks (all sections + all blocks of the ‘source data field variable part’)
/// \post the bytestream is decoded
virtual bool setPacketValue(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField, int decodeType);
/// 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
/// \param packet This is the packet
/// \param decodeType (0) do not decode anything (1) decode only sections (prefix, header, data field header, source data field fixed part, source data field variable part) (2) decode blocks (all sections + all blocks of the ‘source data field variable part’)
/// \post the bytestream is decoded
virtual bool setPacketValue(ByteStreamPtr prefix, ByteStreamPtr packet, int decodeType);
/// 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
/// \param packet This is the packet
/// \return True if the ByteStream contains a packet
virtual bool verifyPacketValue(ByteStreamPtr prefix, ByteStreamPtr packet);
/// Verifies if within the byte* stream passed with arguments it's present a correct packet. The stream* contains also the prefix (if present)
/// \param stream A pointer to the stream of byte, with prefix and packet
virtual bool verifyPacketValue(byte* stream);
/// Sets all the fields of the packet with correct value contained into the input ByteStream.
/// Sets the ByteStream.
/// \param stream A pointer to the stream of byte, with prefix and packet
/// \param decode only the sections
/// \param decodeType (0) do not decode anything (1) decode only sections (prefix, header, data field header, source data field fixed part, source data field variable part) (2) decode blocks (all sections + all blocks of the ‘source data field variable part’)
virtual bool setPacketValue(ByteStreamPtr stream, int decodeType);
/// 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.
/// \param packetHeader This is the header of the packet.
/// \param packetDataField This is the data field of the packet.
/// \return True if the ByteStream contains a packet.
virtual bool verifyPacketValue(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField);
/// \param checkPacketLenght if true check the packet lenght and set the packet stream, if false do not check the packet lenght
virtual bool set(ByteStreamPtr stream, bool checkPacketLenght = false);
/// Sets the ByteStream.
/// \param prefix A pointer to the stream of byte, with the prefix
/// \param packet A pointer to the stream of byte, with the packet
/// \param checkPacketLenght if true check the packet lenght and set the packet stream, if false do not check the packet lenght
virtual bool set(ByteStreamPtr prefix, ByteStreamPtr packet, bool checkPacketLenght = false);
/// Sets the ByteStream.
/// \param prefix A pointer to the stream of byte, with the prefix
/// \param packetHeader A pointer to the stream of byte, with the packet header
/// \param packetHeader A pointer to the stream of byte, with the packet data field
/// \param checkPacketLenght if true check the packet lenght and set the packet stream, if false do not check the packet lenght
virtual bool set(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField, bool checkPacketLenght = false);
///return true is the packet contained into the stream is recognized using identifiers.
///\pre the ByteStream is set with one of set(ByteStream) methods
virtual bool verify();
///Get the prefix as a ByteStream
ByteStreamPtr getBSPrefix();
......@@ -168,19 +145,19 @@ public:
virtual char* printPacketOutputStream();
/// Gets the dimension in byte of the current packet (header + datafield (data field header + sdf + tail)
dword getDimension();
dword size();
/// Get dimension in bytes of the fixed part (without tail) = dim(header) + dim(data field header) + dim(source data field fixed)
inline dword getDimensionFixedPart() { return dimPacketStartingFixedPart; };
inline dword sizeFixedPart() { return dimPacketStartingFixedPart; };
/// Get dimension of the prefix
inline dword getDimensionPrefix() { return dimPrefix; };
inline dword sizePrefix() { return dimPrefix; };
/// Get dimension of the tail
inline dword getDimensionTail() { return dimPacketTail; };
inline dword sizeTail() { return dimPacketTail; };
/// Gets the max dimension in byte of the packet.
dword getMaxDimension();
dword sizeMax();
/// Gets the ByteStream received as input
......@@ -229,6 +206,16 @@ public:
protected:
/// 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
/// \param packetHeader This is the header of the packet
/// \param packetDataField This is the data field of the packet
/// \param decodeType (0) do not decode anything (1) decode only sections (prefix, header, data field header, source data field fixed part, source data field variable part) (2) decode blocks (all sections + all blocks of the ‘source data field variable part’)
/// \post the bytestream is decoded
virtual bool setPacketValue(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField, int decodeType);
/// This attribute represents the packet header.
PacketHeader *header;
......@@ -244,12 +231,12 @@ protected:
/// The ByteStrem of the packet read
ByteStreamPtr packet;
/// The ByteStrem of the packet read
ByteStreamPtr stream;
/// Set the internal prefix and packet.
virtual void setByteStreamPointers(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField);
void setByteStreamSections();
/// Set the internal prefix and packet.
virtual void setByteStreamPointers(ByteStreamPtr prefix, ByteStreamPtr packet);
/// Generates the stream for output.
/// \pre the number of block and the number of element for each block
......@@ -288,10 +275,6 @@ protected:
bool setPacketValueTail(ByteStreamPtr packetDataField);
void memByteStream(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField);
void memByteStream(ByteStreamPtr prefix, ByteStreamPtr packet);
bool bigendian;
bool thereisprefix;
......@@ -327,6 +310,14 @@ private:
///dimPacketHeader + dimPacketDataFieldHeader + dimPacketSourceDataFieldFixed
dword dimPacketStartingFixedPart;
bool decodedPacketHeader;
bool decodedPacketDataFieldHeader;
bool decodedPacketSourceDataField;
bool decodedPacketTail;
};
}
......
......@@ -38,10 +38,10 @@ public:
~PacketDataField();
/// Total dimension in bytes of data field.
dword getDimension();
dword size();
/// Total max dimension in bytes of data field.
dword getMaxDimension();
dword sizeMax();
/// Creates the outputstream ByteStream for the generation of the output stream
virtual bool setOutputStream(ByteStreamPtr os, word first);
......
......@@ -50,7 +50,7 @@ public:
Field * getFieldWithPacketDimension();
inline word getDimensionOfPacketLength()
inline word sizeOfPacketLength()
{
return dimensionOfPacketLength;
};
......
......@@ -41,7 +41,7 @@ public:
/// \pre the prefix has been removed
/// \param packet the stream that contains the source packet without the prefix
/// \param decodeType (0) do not decode anything (1) decode only sections (prefix, header, data field header, source data field fixed part, source data field variable part) (2) decode blocks (all sections + all blocks of the ‘source data field variable part’)
Packet* getPacket(ByteStreamPtr packet, int decodeType = 2) throw(PacketException*);
Packet* getPacket(ByteStreamPtr stream) throw(PacketException*);
/// \return The index of packet type if it's recognized. 0 if packet isn't recognized.
/// \param prefix A ByteStream that contains the prefix of packet (if present).
......
......@@ -65,7 +65,7 @@ public:
virtual MemoryBuffer* loadFieldsInBuffer(InputText & fp);
/// Returns the dimension (in byte) of this part of packet.
virtual inline dword getDimension()
virtual inline dword size()
{
return fieldsDimension / 8;
};
......
......@@ -111,9 +111,9 @@ public:
/// \param rBlockIndex the number of the rblock
virtual SDFBlock* getBlock(word nblock, word rBlockIndex);
virtual dword getMaxDimension();
virtual dword sizeMax();
virtual dword getDimension();
virtual dword size();
/// Set the number of blocks (the number of times that a block of a
/// determinated type is repeated) for each type of rblock present.
......
......@@ -68,11 +68,11 @@ public:
/// Returns the number of fields.
virtual word getNumberOfFields();
virtual dword getMaxDimension();
virtual dword sizeMax();
virtual dword getDimension();
virtual dword size();
virtual dword getDimensionFixedPart();
virtual dword sizeFixedPart();
//onlySections = false
virtual bool setByteStream(ByteStreamPtr s, int decodeType);
......
......@@ -71,7 +71,7 @@ PacketLib::ByteStream::ByteStream(ByteStreamPtr b0, dword start, dword end, bool
mem_allocation_constructor = true;
if(end == -1)
end = b0->getDimension();
end = b0->size();
byteInTheStream = end-start;
this->stream = b0->stream+start;
......@@ -100,24 +100,24 @@ PacketLib::ByteStream::ByteStream(ByteStreamPtr b0, ByteStreamPtr b1, ByteStream
mem_allocation_constructor = false;
return;
}
byteInTheStream = (b0!=0?b0->getDimension():0) + (b1!=0?b1->getDimension():0) + (b2!=0?b2->getDimension():0);
byteInTheStream = (b0!=0?b0->size():0) + (b1!=0?b1->size():0) + (b2!=0?b2->size():0);
stream = (byte*) new byte[byteInTheStream];
this->bigendian = (b0!=0?b0->isBigendian():(b1!=0?b1->isBigendian():(b2!=0?b2->isBigendian():false)));
if(b0 != 0)
{
memcpy(stream, b0->stream, b0->getDimension());
dim += b0->getDimension();
memcpy(stream, b0->stream, b0->size());
dim += b0->size();
}
if(b1 != 0)
{
memcpy(stream+dim, b1->stream, b1->getDimension());
dim += b1->getDimension();
memcpy(stream+dim, b1->stream, b1->size());
dim += b1->size();
}
if(b2 != 0)
{
memcpy(stream+dim, b2->stream, b2->getDimension());
dim += b2->getDimension();
memcpy(stream+dim, b2->stream, b2->size());
dim += b2->size();
}
setMemoryAllocated(true);
mem_allocation_constructor = false;
......@@ -240,7 +240,7 @@ void PacketLib::ByteStream::endOutputStream()
}
dword PacketLib::ByteStream::getDimension()
dword PacketLib::ByteStream::size()
{
return byteInTheStream;
}
......@@ -286,7 +286,7 @@ bool PacketLib::ByteStream::setStream(ByteStreamPtr b, dword first, dword last)
{
if(first > last)
return false;
if(last > b->getDimension())
if(last > b->size())
return false;
deleteStreamMemory();
......
......@@ -306,7 +306,7 @@ bool File::writeString(const char* str) throw(PacketExceptionIO*)
bool File::writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*)
{
byte* stream = b->getOutputStream();
if(fwrite((void*)stream, b->getDimension(), 1, fp)<1)
if(fwrite((void*)stream, b->size(), 1, fp)<1)
throw new PacketExceptionIO("Can't write stream in the file.");
b->endOutputStream();
return true;
......
......@@ -58,7 +58,7 @@ ByteStreamPtr InputFile::readByteStream(dword n_byte) throw(PacketExceptionIO*)
return 0;
closed = file->isClosed();
eof = file->isEOF();
if(bs->getDimension() == 0) return 0;
if(bs->size() == 0) return 0;
return bs;
}
......
......@@ -48,7 +48,7 @@ void InputPacketStream::setInput(Input* in)
Packet* InputPacketStream::readPacket(int decodeType) throw(PacketExceptionIO*)
Packet* InputPacketStream::readPacket() throw(PacketExceptionIO*)
{
unsigned dimHeader = getHeaderDimension();
unsigned dimPrefix = getPrefixDimension();
......@@ -74,9 +74,9 @@ Packet* InputPacketStream::readPacket(int decodeType) throw(PacketExceptionIO*)
else
return 0;
}
if(b1->getDimension() != dimHeader)
if(b1->size() != dimHeader)
{
if(b1->getDimension() != 0)
if(b1->size() != 0)
pindex = 0;
else
throw new PacketExceptionIO("it is impossible to read the full header.");
......@@ -93,7 +93,7 @@ Packet* InputPacketStream::readPacket(int decodeType) throw(PacketExceptionIO*)
else
return 0;
}
dim= b2->getDimension();
dim= b2->size();
if(dim != pl)
{
if(dim != 0)
......@@ -108,7 +108,7 @@ Packet* InputPacketStream::readPacket(int decodeType) throw(PacketExceptionIO*)
Packet* p = packetType[pindex];
if(!p->setPacketValue(b0, b1, b2, decodeType)) //gli stream diventano del packet
if(!p->set(b0, b1, b2)) //gli stream diventano del packet
throw new PacketExceptionIO("it is impossible to resolve the packet.");
return p;
......
......@@ -103,7 +103,7 @@ bool InputPacketStreamFile::freeRun() throw(PacketExceptionIO*)
numberOfFileStreamPointer = 0;
inputStream->setFirstPos();
long count = 0;
unsigned dimHeader = headerReference->getDimension();
unsigned dimHeader = headerReference->size();
while(!inputStream->isEOF())
{
int pindex = 0;
......@@ -113,9 +113,9 @@ bool InputPacketStreamFile::freeRun() throw(PacketExceptionIO*)
return true;
b1 = inputStream->readHeader(dimHeader);
if(b1->getDimension() != dimHeader)
if(b1->size() != dimHeader)
{
if(b1->getDimension() != 0)
if(b1->size() != 0)
pindex = 0;
else
{
......@@ -128,7 +128,7 @@ bool InputPacketStreamFile::freeRun() throw(PacketExceptionIO*)
headerReference->setByteStream(b1);
pl = headerReference->getPacketLength();
b2 = inputStream->readDataField(pl);
dim= b2->getDimension();
dim= b2->size();
if(dim != pl)
{
if(dim != 0)
......@@ -190,7 +190,7 @@ Packet* InputPacketStreamFile::getPacketFromFileStreamPointer(int index, bool ne
type = it->typeOfPacket;
pos = it->pointerStart;
inputStream->setpos(pos);
int dimHeader = headerReference->getDimension();
int dimHeader = headerReference->size();
b0 = inputStream->readPrefix();
if((b1 = inputStream->readHeader(dimHeader)) == NULL)
return NULL;
......@@ -211,7 +211,7 @@ Packet* InputPacketStreamFile::getPacketFromFileStreamPointer(int index, bool ne
pnew->createPacketType((char*)sf.c_str(), prefix, dimPrefix);
p = pnew;
}
if(p->setPacketValue(b0, b1, b2, 2))
if(p->set(b0, b1, b2))
return p;
else
return NULL;
......@@ -267,7 +267,7 @@ Packet* InputPacketStreamFile::getPacketFromStream() throw (PacketExceptionIO *
{
ByteStreamPtr b0, b1, b2;
word pl, dim;
unsigned dimHeader = headerReference->getDimension();
unsigned dimHeader = headerReference->size();
if(inputStream->isEOF())
return 0;
......@@ -275,13 +275,13 @@ Packet* InputPacketStreamFile::getPacketFromStream() throw (PacketExceptionIO *
if(inputStream->isEOF())
return 0;
b1 = inputStream->readHeader(dimHeader);
if(b1->getDimension() != dimHeader)
if(b1->size() != dimHeader)
return 0;
headerReference->setByteStream(b1);
pl = headerReference->getPacketLength();
b2 = inputStream->readDataField(pl);
dim = b2->getDimension();
dim = b2->size();
if(dim != pl)
return 0;
......@@ -289,7 +289,8 @@ Packet* InputPacketStreamFile::getPacketFromStream() throw (PacketExceptionIO *
for (int i = 1; i<numberOfPacketType; i++)
{
p = getPacketType(i);
if(p->setAndVerifyPacketValue(b0, b1, b2))
p->set(b0, b1, b2);
if(p->verify())
{
return p;
}
......
......@@ -84,7 +84,7 @@ ByteStreamPtr InputSerial::readByteStream(int n_byte) throw(PacketExceptionIO*)
//for(int i=0; i<n_byte; i++)
//printf("%d: %x\n", i, buff[i]);
if(bs->getDimension() == 0)
if(bs->size() == 0)
return 0;
return bs;
}
......
......@@ -56,7 +56,7 @@ bool OutputSerial::open(char** parameters) throw(PacketExceptionIO*)
bool OutputSerial::writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*)
{
byte* buff = b->getStream();
unsigned n_byte = b->getDimension();
unsigned n_byte = b->size();
if(!isclosed)
if( serial->write( buff, n_byte ) > 0 )
......
This diff is collapsed.
......@@ -37,22 +37,22 @@ PacketDataField::~PacketDataField()
dword PacketDataField::getDimension()
dword PacketDataField::size()
{
if(sourceDataField != 0)
return dataFieldHeader->getDimension() + sourceDataField->getDimension() + tail->getDimension();
return dataFieldHeader->size() + sourceDataField->size() + tail->size();
else
return dataFieldHeader->getDimension() + tail->getDimension();
return dataFieldHeader->size() + tail->size();
}
dword PacketDataField::getMaxDimension()
dword PacketDataField::sizeMax()
{
if(sourceDataField != 0)
return dataFieldHeader->getDimension() + sourceDataField->getMaxDimension() + tail->getDimension();
return dataFieldHeader->size() + sourceDataField->sizeMax() + tail->size();
else
return dataFieldHeader->getDimension() + tail->getDimension();
return dataFieldHeader->size() + tail->size();
}
......@@ -63,14 +63,14 @@ dword PacketDataField::getMaxDimension()
bool PacketDataField::setOutputStream(ByteStreamPtr os, word first)
{
outputstream = ByteStreamPtr(new ByteStream((os->stream + first), getDimension(), os->isBigendian()));
outputstream = ByteStreamPtr(new ByteStream((os->stream + first), size(), os->isBigendian()));
dataFieldHeader->setOutputStream(os, first);
word sdfstart = first + dataFieldHeader->getDimension();
word sdfstart = first + dataFieldHeader->size();
sourceDataField->setOutputStream(os, sdfstart);
word tailstart = sdfstart;
if(sourceDataField != 0)
tailstart += sourceDataField->getDimension();
if(tail->getDimension() != 0)
tailstart += sourceDataField->size();
if(tail->size() != 0)
tail->setOutputStream(os, tailstart);
return true;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment