Skip to content

Commit e37eda8

Browse files
author
Zachary Crockett
committed
Merge pull request #8 from spark/bug-fixes
Verify chunk_saved_status logic - make OTA Update more reliable
2 parents 6fbe5af + 56740df commit e37eda8

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/spark_protocol.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -876,9 +876,16 @@ bool SparkProtocol::handle_received_message(void)
876876
unsigned int given_crc = queue[8] << 24 | queue[9] << 16 | queue[10] << 8 | queue[11];
877877
if (callback_calculate_crc(queue + 13, len - 13 - queue[len - 1]) == given_crc)
878878
{
879-
callback_save_firmware_chunk(queue + 13, len - 13 - queue[len - 1]);
880-
chunk_received(msg_to_send + 2, token, ChunkReceivedCode::OK);
881-
++chunk_index;
879+
unsigned short next_chunk_index = callback_save_firmware_chunk(queue + 13, len - 13 - queue[len - 1]);
880+
if (next_chunk_index > chunk_index)
881+
{
882+
chunk_received(msg_to_send + 2, token, ChunkReceivedCode::OK);
883+
}
884+
else
885+
{
886+
chunk_missed(msg_to_send + 2, next_chunk_index);
887+
}
888+
chunk_index = next_chunk_index;
882889
}
883890
else
884891
{

src/spark_protocol.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct SparkCallbacks
6464
void (*prepare_for_firmware_update)(void);
6565
void (*finish_firmware_update)(void);
6666
long unsigned int (*calculate_crc)(unsigned char *buf, long unsigned int buflen);
67-
void (*save_firmware_chunk)(unsigned char *buf, long unsigned int buflen);
67+
unsigned short (*save_firmware_chunk)(unsigned char *buf, long unsigned int buflen);
6868
void (*signal)(bool on);
6969
system_tick_t (*millis)();
7070
};
@@ -142,7 +142,7 @@ class SparkProtocol
142142
void (*callback_prepare_for_firmware_update)(void);
143143
void (*callback_finish_firmware_update)(void);
144144
long unsigned int (*callback_calculate_crc)(unsigned char *buf, long unsigned int buflen);
145-
void (*callback_save_firmware_chunk)(unsigned char *buf, long unsigned int buflen);
145+
unsigned short (*callback_save_firmware_chunk)(unsigned char *buf, long unsigned int buflen);
146146
void (*callback_signal)(bool on);
147147
system_tick_t (*callback_millis)();
148148

0 commit comments

Comments
 (0)