Commit 4ce389fb authored by Andrea Bulgarelli's avatar Andrea Bulgarelli
Browse files

InputPacketStream::getPacketDimension(byte* stream),...

InputPacketStream::getPacketDimension(byte* stream), InputPacketStream::detPacketType(byte* packet), Packet::verifyPacketValue(byte* stream)
parent a4dbe41a
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
2013-09-17  Andrea Bulgarelli <bulgarelli@iasfbo.inaf.it>

* include/InputPacketStream.h (InputPacketStream): 
        ** dword getPacketDimension(byte* stream);
        ** int detPacketType(byte* packet);
* include/Packet.h (Packet): bool verifyPacketValue(byte* stream);


2013-09-13  Andrea Bulgarelli <bulgarelli@iasfbo.inaf.it>
TAG v2.0.7
* src/PartOfPacket.cpp (PartOfPacket::setByteStream): 
+11 −2
Original line number Diff line number Diff line
@@ -36,17 +36,26 @@ public:

    ~InputPacketStream();

    /// \return The index of packet type if it's recognized. 0 if packet isn't recogniezed.
    /// \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).
    /// \param packetHeader A ByteStream that contains the packet header.
    /// \param packetDataField A ByteStream that contains the packet data field.
    int detPacketType(ByteStream* prefix, ByteStream* packetHeader, ByteStream* packetDataField);

   /// \return The index of packet type if it's recognized. 0 if packet isn't recogniezed.
    /// \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).
    /// \param packet A ByteStream that contains the packet.
    int detPacketType(ByteStream* prefix, ByteStream* packet);

    ///It returns the index of the packet type contained in the stream. The stream* contains also the prefix (if present)
    /// \return The index of packet type if it's recognized. 0 if packet isn't recognized.
    /// \param packet A byte* that contains the packet.
    int detPacketType(byte* packet);

	///It returns the total dimension of the packet contained in the stream (without prefix). The stream* contains also the prefix (if present)
	///\param The stream with the prefix (if present)
    dword getPacketDimension(byte* stream);

    /// This method sets the generic input of the stream
    /// \param in An input.
    void setInput(Input* in);
+4 −0
Original line number Diff line number Diff line
@@ -86,6 +86,10 @@ public:
    /// \return True if the ByteStream contains a packet
    bool verifyPacketValue(ByteStream* prefix, ByteStream* 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
    bool verifyPacketValue(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.
+29 −0
Original line number Diff line number Diff line
@@ -69,6 +69,18 @@ int InputPacketStream::detPacketType(ByteStream* prefix, ByteStream* packet)
}


int InputPacketStream::detPacketType(byte* packet)
{
    /// Iterate through list and output each element.
    /// The packetType 0 is the packet not recognized
    for (dword i = 1; i<numberOfPacketType; i++)
    {
        Packet* p = getPacketType(i);
        if(p->verifyPacketValue(packet))
            return i;
    }
    return 0;
}

void InputPacketStream::setInput(Input* in)
{
@@ -145,3 +157,20 @@ Packet* InputPacketStream::readPacket() throw(PacketExceptionIO*)
        throw e;
    }
}

dword InputPacketStream::getPacketDimension(byte* stream) {
		dword dimPre = 0;
		if(prefix)
			dimPre += dimPrefix;
		//ByteStream* prefix = new ByteStream(stream, dimPre, bigendian);

		dword dim = 0;
		dword dimHeader = headerReference->getDimension();
		dim += dimHeader;
		ByteStream* tempHeader = new ByteStream();
		tempHeader->setStream(stream+dimPre, dimHeader, bigendian);
		headerReference->setByteStream(tempHeader);
		dim += headerReference->getPacketLength();
		delete tempHeader;
		return dim;
}
+19 −0
Original line number Diff line number Diff line
@@ -835,3 +835,22 @@ char* Packet::printPacketOutputStream()
    char* c = b.printStreamInHexadecimal();
    return c;
}

bool Packet::verifyPacketValue(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 verifyPacketValue(prefix, packet);
}
Loading