Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ void from_buffer (Img& i, Buffer& b) {
i.image_id = static_cast<uint8_t>(b.get(8));
i.fragment_id = static_cast<uint16_t>(b.get(16));
i.num_fragments = static_cast<uint16_t>(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);
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

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.

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)

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

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)

std::copy(image_data, image_data+num_bytes, i.image_data);
}

void from_buffer (Health& h, Buffer& b) {
Expand Down
2 changes: 1 addition & 1 deletion app/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class Archive>
void serialize (Archive& ar) {
Expand Down