From 09c10a0a6a2f110d05e19e6b8d275d70ed083d3a Mon Sep 17 00:00:00 2001 From: sl1g18 <43995115+sl1g18@users.noreply.github.com> Date: Thu, 31 Jan 2019 13:15:54 +0000 Subject: [PATCH 1/2] Added image packet parsing The image payload is assumed to be located between the end of the 'number of fragments' and the last 144 bits of the packet, which are supposed to be the Hash/CRC bits. --- app/packet.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/packet.cpp b/app/packet.cpp index eb8dff4..91de094 100644 --- a/app/packet.cpp +++ b/app/packet.cpp @@ -72,8 +72,13 @@ void from_buffer (Img& i, Buffer& b) { i.image_id = static_cast(b.get(8)); i.fragment_id = static_cast(b.get(16)); i.num_fragments = static_cast(b.get(16)); - char image_data[6] = { 'i', 'm', 'a', 'g', 'e', '\0' }; - std::copy(image_data, image_data+6, i.image_data); + char image_data[76]; + uint64_t fragment_len = b.len()-(b.pos()+144); + uint32_t num_bytes = fragment_len/8; + uint8_t num_bits = fragment_len%8; + for(int i=0; ib.get(8); } + image_data[num_bytes] = static_castb.get(num_bits); + std::copy(image_data, image_data+num_bytes, i.image_data); } void from_buffer (Health& h, Buffer& b) { From 036df2268b45cd539825a0c1e0a0998016ee8537 Mon Sep 17 00:00:00 2001 From: sl1g18 <43995115+sl1g18@users.noreply.github.com> Date: Thu, 31 Jan 2019 13:22:42 +0000 Subject: [PATCH 2/2] Updated image_data size to 76 bytes The maximum payload size of the image packet is 602 bits, which amounts to 75 bytes + 2 extra bits, hence the 76 bytes size change. --- app/packet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/packet.h b/app/packet.h index ddc15c2..43da169 100644 --- a/app/packet.h +++ b/app/packet.h @@ -197,7 +197,7 @@ struct Img { uint8_t image_id; uint16_t fragment_id; uint16_t num_fragments; - char image_data[6]; // TODO: replace once size is finalized + char image_data[76]; template void serialize (Archive& ar) {