Skip to content
Snippets Groups Projects
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
Branches
Tags
No related merge requests found
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> 2013-09-13 Andrea Bulgarelli <bulgarelli@iasfbo.inaf.it>
TAG v2.0.7 TAG v2.0.7
* src/PartOfPacket.cpp (PartOfPacket::setByteStream): * src/PartOfPacket.cpp (PartOfPacket::setByteStream):
......
...@@ -36,17 +36,26 @@ public: ...@@ -36,17 +36,26 @@ public:
~InputPacketStream(); ~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 prefix A ByteStream that contains the prefix of packet (if present).
/// \param packetHeader A ByteStream that contains the packet header. /// \param packetHeader A ByteStream that contains the packet header.
/// \param packetDataField A ByteStream that contains the packet data field. /// \param packetDataField A ByteStream that contains the packet data field.
int detPacketType(ByteStream* prefix, ByteStream* packetHeader, ByteStream* packetDataField); 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 prefix A ByteStream that contains the prefix of packet (if present).
/// \param packet A ByteStream that contains the packet. /// \param packet A ByteStream that contains the packet.
int detPacketType(ByteStream* prefix, ByteStream* 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 /// This method sets the generic input of the stream
/// \param in An input. /// \param in An input.
void setInput(Input* in); void setInput(Input* in);
......
...@@ -86,6 +86,10 @@ public: ...@@ -86,6 +86,10 @@ public:
/// \return True if the ByteStream contains a packet /// \return True if the ByteStream contains a packet
bool verifyPacketValue(ByteStream* prefix, ByteStream* 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. /// Verifies if within the ByteStream passed with arguments it's present a correct packet.
/// \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.
......
...@@ -69,6 +69,18 @@ int InputPacketStream::detPacketType(ByteStream* prefix, ByteStream* packet) ...@@ -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) void InputPacketStream::setInput(Input* in)
{ {
...@@ -145,3 +157,20 @@ Packet* InputPacketStream::readPacket() throw(PacketExceptionIO*) ...@@ -145,3 +157,20 @@ Packet* InputPacketStream::readPacket() throw(PacketExceptionIO*)
throw e; 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;
}
...@@ -835,3 +835,22 @@ char* Packet::printPacketOutputStream() ...@@ -835,3 +835,22 @@ char* Packet::printPacketOutputStream()
char* c = b.printStreamInHexadecimal(); char* c = b.printStreamInHexadecimal();
return c; 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);
}
2.0.1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment