Conversation
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.
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.
| uint32_t num_bytes = fragment_len/8; | ||
| uint8_t num_bits = fragment_len%8; | ||
| for(int i=0; i<num_bytes; i++) { image_data[i] = static_cast<char>b.get(8); } | ||
| image_data[num_bytes] = static_cast<char>b.get(num_bits); |
There was a problem hiding this comment.
this has some spaces in its indentation
| 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); |
There was a problem hiding this comment.
these should be get_len and get_pos
| uint32_t num_bytes = fragment_len/8; | ||
| uint8_t num_bits = fragment_len%8; | ||
| for(int i=0; i<num_bytes; i++) { image_data[i] = static_cast<char>b.get(8); } | ||
| image_data[num_bytes] = static_cast<char>b.get(num_bits); |
There was a problem hiding this comment.
there should be parens around b.get(num_bits)
| 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; i<num_bytes; i++) { image_data[i] = static_cast<char>b.get(8); } |
There was a problem hiding this comment.
there should be parens around b.get(8)
| 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); |
There was a problem hiding this comment.
b.get_len() is in bytes, whereas b.get_pos() is in bits (I appreciate that's pretty weird, and it might be nice to change the length to be in bits too)... however, if I try (b.get_len() * 8) - (b.get_pos() + 144) I get back 2656 bits, which is 332 bytes. I appreciate that I could be wrong about the size (I've only got the Excel spreadsheet to go off and I've had to guess intent a couple of times), and if I change the declared length of image_data from 76 to 332 with the other fixes it seems to work (or at least it spits out some json), so I'll sort of leave it up to you on how to proceed, as long as it all works in the end.
I had no way of testing this, so hopefully it works alright.