From 8d67321d4ba1fe68d07720fff34833971a64708a Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 22 Nov 2021 21:26:47 +0100 Subject: [PATCH] Implemented payload-alanyzing (size) --- handler/textPacketHandler.hpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/handler/textPacketHandler.hpp b/handler/textPacketHandler.hpp index f4d99c1..095e193 100644 --- a/handler/textPacketHandler.hpp +++ b/handler/textPacketHandler.hpp @@ -30,13 +30,18 @@ const std::unordered_map PACKET_TYPE_MAP({ }); void parseHeader(Packet &packet, const std::vector &textPacket); +void parsePayload(Packet &packet, const std::vector &textPacket); + void textPacketHandler(const std::vector textPacket){ /// Here we have to parse the packet // Create empty packet Packet packet; parseHeader(packet, textPacket); + parsePayload(packet, textPacket); } + + void parseHeader(Packet &packet, const std::vector &textPacket){ const std::string textHeader = textPacket[0]; @@ -149,7 +154,24 @@ void parseHeader(Packet &packet, const std::vector &textPacket){ } - // +void parsePayload(Packet &packet, const std::vector &textPacket){ + + // Expect max of 16byte per line of payload + unsigned int payloadSize = 16*(textPacket.size()-1); + + // Go through last line + int line = textPacket.size()-1, charPos; + for(int f=0; f<8*2; ++f){ + charPos = 10 + (f/2.0*5); + + if(textPacket[line][charPos] == ' ') { // When our char is space, no more data is present + // Set size + payloadSize = 16*(textPacket.size()-2)+f; + break; + } + } + + packet.payloadSize = payloadSize; } #endif /* EE781A91_6D07_47AC_B3C4_F99E29F3731F */