@@ -24,6 +24,10 @@ class LoraOTA:
2424 MSG_HEADER = b'$OTA'
2525 MSG_TAIL = b'*'
2626
27+ FULL_UPDATE = b'F'
28+ DIFF_UPDATE = b'D'
29+ NO_UPDATE = b'N'
30+
2731 UPDATE_INFO_MSG = 1
2832 UPDATE_INFO_REPLY = 2
2933
@@ -46,6 +50,7 @@ def __init__(self, lora):
4650 self .version_file = '/flash/OTA_INFO.py'
4751 self .update_version = '0.0.0'
4852 self .update_time = - 1
53+ self .update_type = None
4954 self .resp_received = False
5055 self .update_in_progress = False
5156 self .operation_timeout = 10
@@ -221,13 +226,13 @@ def parse_update_info_reply(self, msg):
221226
222227 try :
223228 token_msg = msg .split ("," )
224- need_updating = int ( token_msg [2 ] )
225- if need_updating :
226- self .update_version = token_msg [3 ]
227- self .update_time = int (token_msg [5 ])
229+ self . update_type = token_msg [3 ]. encode ( )
230+ if self . update_type in [ self . FULL_UPDATE , self . DIFF_UPDATE ] :
231+ self .update_version = token_msg [2 ]
232+ self .update_time = int (token_msg [4 ])
228233
229234 if utime .time () < 1550000000 :
230- self .sync_clock (int (token_msg [4 ]))
235+ self .sync_clock (int (token_msg [5 ]))
231236
232237 except Exception as ex :
233238 print ("Exception getting update information: {}" .format (ex ))
@@ -374,7 +379,8 @@ def apply_patches(self):
374379
375380 to_patch = ''
376381 print ('Updating file: {}' .format (key ))
377- if self .file_exists ('/flash/' + key ):
382+ if self .update_type == self .DIFF_UPDATE and \
383+ self .file_exists ('/flash/' + key ):
378384 to_patch = self ._read_file (key )
379385
380386 patched_text , success = self .dmp .patch_apply (self .patch_list , to_patch )
@@ -426,7 +432,7 @@ def manifest_failure(self, msg):
426432 return False
427433
428434 def process_manifest_msg (self , msg ):
429-
435+
430436 if self .manifest_failure (msg ):
431437 print ('Manifest failure: Discarding update ...' )
432438 self .reset_update_params ()
@@ -443,7 +449,8 @@ def process_manifest_msg(self, msg):
443449 def process_filename_msg (self , msg ):
444450 self .file_to_patch = self .get_msg_data (msg )
445451
446- if self .file_exists ('/flash/' + self .file_to_patch ):
452+ if self .update_type == self .DIFF_UPDATE and \
453+ self .file_exists ('/flash/' + self .file_to_patch ):
447454 self .device_mainfest ["update" ] += 1
448455 print ("Update file: {}" .format (self .file_to_patch ))
449456 else :
0 commit comments