Commit a7cfcad8 authored by Andrea Bulgarelli's avatar Andrea Bulgarelli
Browse files

Merge remote-tracking branch 'origin/optimize'

Conflicts:
	include/SourceDataField.h
	src/ByteStream.cpp
	src/InputPacketStream.cpp
	src/Packet.cpp
parents 71838da3 6d741615
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -62,8 +62,9 @@ public:


    /// This method read a telemetry packet
    /// This method read a telemetry packet
    /// \pre The setInput method must be invocated
    /// \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!
    /// \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);
    Packet* decodePacket(ByteStreamPtr stream);


+3 −0
Original line number Original line Diff line number Diff line
@@ -64,6 +64,9 @@ public:
    /// correct value
    /// correct value
    virtual bool setAndVerifyPacketValue(ByteStreamPtr prefix, ByteStreamPtr packet);
    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.
    /// Sets all the fields of the packet with correct value contained into the input ByteStream.
    ///	\pre The structure of the stream must be loaded.
    ///	\pre The structure of the stream must be loaded.
    /// \param prefix This is the prefix of the packet
    /// \param prefix This is the prefix of the packet
+1 −1
Original line number Original line Diff line number Diff line
@@ -34,7 +34,7 @@ public:
    virtual ~SourceDataField();
    virtual ~SourceDataField();
	
	
	/// Sets the stream of byte. This method assigns the value of stream for each field of part of packet
	/// 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
    /// Gets the total max dimension in bytes of source data field
    virtual dword getMaxDimension() = 0;
    virtual dword getMaxDimension() = 0;
+16 −30
Original line number Original line Diff line number Diff line
@@ -97,7 +97,6 @@ PacketLib::ByteStream::ByteStream(ByteStreamPtr b0, ByteStreamPtr b1, ByteStream
    mem_allocation_constructor = true;
    mem_allocation_constructor = true;


    /// Streams are swapped
    /// Streams are swapped
    dword i = 0;
    dword dim = 0;
    dword dim = 0;
    if(b0 == 0 && b1 == 0 && b2 == 0)
    if(b0 == 0 && b1 == 0 && b2 == 0)
    {
    {
@@ -113,33 +112,20 @@ PacketLib::ByteStream::ByteStream(ByteStreamPtr b0, ByteStreamPtr b1, ByteStream
    stream = (byte*) new byte[byteInTheStream];
    stream = (byte*) new byte[byteInTheStream];
    this->bigendian = (b0!=0?b0->isBigendian():(b1!=0?b1->isBigendian():(b2!=0?b2->isBigendian():false)));
    this->bigendian = (b0!=0?b0->isBigendian():(b1!=0?b1->isBigendian():(b2!=0?b2->isBigendian():false)));


	//TODO AZ: fare il memcpy
	
	if(b0 != 0)
	if(b0 != 0)
	{
	{
        dim = b0->getDimension();
		memcpy(stream, b0->stream, b0->getDimension());
        for(; i<b0->getDimension(); i++)
		dim += b0->getDimension();
            stream[i] = b0->stream[i];
	}
	}
	if(b1 != 0)
	if(b1 != 0)
	{
	{
		memcpy(stream+dim, b1->stream, b1->getDimension());
		dim += b1->getDimension();
		dim += b1->getDimension();
        dword istart = i;
        for(; i<dim; i++)
        {
            dword pos = i-istart;
            stream[i] = b1->stream[pos];
        }
	}
	}
	if(b2 != 0)
	if(b2 != 0)
	{
	{
		memcpy(stream+dim, b2->stream, b2->getDimension());
		dim += b2->getDimension();
		dim += b2->getDimension();
        dword istart = i;
        for(; i<dim; i++)
        {
            dword pos = i-istart;
            stream[i] = b2->stream[pos];
        }
	}
	}
    setMemoryAllocated(true);
    setMemoryAllocated(true);
    mem_allocation_constructor = false;
    mem_allocation_constructor = false;
+7 −40
Original line number Original line Diff line number Diff line
@@ -108,49 +108,16 @@ int File::getByte()


ByteStreamPtr File::getNByte(dword N)
ByteStreamPtr File::getNByte(dword N)
{
{
    dword i = 0;
    int c1, c2;
	if(N == 0)
	if(N == 0)
		return ByteStreamPtr(new ByteStream(0, bigendian));
		return ByteStreamPtr(new ByteStream(0, bigendian));
    //solo un numero pari di byte
    //if(N%2 != 0 || !fileOpened) return NULL;

    if(closed) return NULL;


    //ByteStreamPtr b = new ByteStream(N, bigendian);
    byte* stream = (byte*) new byte[N];
    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; i<N && (c1 = getByte()) != EOI && (c2 = getByte()) != EOI; i+=2)
    return ByteStreamPtr(new ByteStream(stream, result, bigendian, false));
    {
        //File::byte_read += 2;
        stream[i] = c1;
        stream[i+1] = c2;
        /*        if(bigendian)
                {
                    //se la  macchina e' bigendian, non e' necessario effettuare scambi di byte
                    b->stream[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; j<i; j++)
            b1->stream[j] = b->stream[j];
        delete b;
        b = b1;
    } */
    //for(; i<N; i++)
    //	b->stream[i] = 0;
    //return b;
    return ByteStreamPtr(new ByteStream(stream, i, bigendian, false));
}
}




Loading