Skip to content

Conversation

@sl1g18
Copy link

@sl1g18 sl1g18 commented Jan 31, 2019

I had no way of testing this, so hopefully it works alright.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Member

@charlie-wt charlie-wt Feb 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants