File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed
Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -793,6 +793,8 @@ bool SparkProtocol::handle_received_message(void)
793793 int return_value = descriptor.call_function (function_key, function_arg);
794794
795795 // send return value
796+ *msg_to_send = 0 ;
797+ *(msg_to_send + 1 ) = 16 ;
796798 function_return (msg_to_send + 2 , token, return_value);
797799 if (0 > blocking_send (msg_to_send, 18 ))
798800 {
@@ -874,9 +876,16 @@ bool SparkProtocol::handle_received_message(void)
874876 unsigned int given_crc = queue[8 ] << 24 | queue[9 ] << 16 | queue[10 ] << 8 | queue[11 ];
875877 if (callback_calculate_crc (queue + 13 , len - 13 - queue[len - 1 ]) == given_crc)
876878 {
877- callback_save_firmware_chunk (queue + 13 , len - 13 - queue[len - 1 ]);
878- chunk_received (msg_to_send + 2 , token, ChunkReceivedCode::OK);
879- ++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;
880889 }
881890 else
882891 {
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments