Skip to content

Commit

Permalink
Merge pull request #8 from spark/bug-fixes
Browse files Browse the repository at this point in the history
Verify chunk_saved_status logic - make OTA Update more reliable
  • Loading branch information
Zachary Crockett committed Apr 13, 2014
2 parents 6fbe5af + 56740df commit e37eda8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/spark_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,9 +876,16 @@ bool SparkProtocol::handle_received_message(void)
unsigned int given_crc = queue[8] << 24 | queue[9] << 16 | queue[10] << 8 | queue[11];
if (callback_calculate_crc(queue + 13, len - 13 - queue[len - 1]) == given_crc)
{
callback_save_firmware_chunk(queue + 13, len - 13 - queue[len - 1]);
chunk_received(msg_to_send + 2, token, ChunkReceivedCode::OK);
++chunk_index;
unsigned short next_chunk_index = callback_save_firmware_chunk(queue + 13, len - 13 - queue[len - 1]);
if (next_chunk_index > chunk_index)
{
chunk_received(msg_to_send + 2, token, ChunkReceivedCode::OK);
}
else
{
chunk_missed(msg_to_send + 2, next_chunk_index);
}
chunk_index = next_chunk_index;
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/spark_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct SparkCallbacks
void (*prepare_for_firmware_update)(void);
void (*finish_firmware_update)(void);
long unsigned int (*calculate_crc)(unsigned char *buf, long unsigned int buflen);
void (*save_firmware_chunk)(unsigned char *buf, long unsigned int buflen);
unsigned short (*save_firmware_chunk)(unsigned char *buf, long unsigned int buflen);
void (*signal)(bool on);
system_tick_t (*millis)();
};
Expand Down Expand Up @@ -142,7 +142,7 @@ class SparkProtocol
void (*callback_prepare_for_firmware_update)(void);
void (*callback_finish_firmware_update)(void);
long unsigned int (*callback_calculate_crc)(unsigned char *buf, long unsigned int buflen);
void (*callback_save_firmware_chunk)(unsigned char *buf, long unsigned int buflen);
unsigned short (*callback_save_firmware_chunk)(unsigned char *buf, long unsigned int buflen);
void (*callback_signal)(bool on);
system_tick_t (*callback_millis)();

Expand Down

0 comments on commit e37eda8

Please sign in to comment.