Commit 8ee22668 authored by aohui.li's avatar aohui.li

优化升级的验证字段

parent 282350fa
......@@ -9,8 +9,7 @@ import os
import threading
import json
import time
import sys
import zlib
import re
#----------------------------------------------------------------------------------------#
# 测试平台
......@@ -39,7 +38,7 @@ mqttConfig = {
# }
dev_type = 'WTG902F'
dev_type = 'WTG906F'
updateCheckInTopic = 'WT/%s/Update/CheckIn' % dev_type
updateResponseTopic = 'WT/%s/Update/Response' % dev_type
......@@ -48,11 +47,10 @@ updateTopic = 'WT/%s/{0}/Update' % dev_type
updateList = [{'sn': '21126112', 'package': 0, 'time': time.time(), 'send': True}]
NewImage = "Gateway.bin"
NewImage = "BIN/v2.35.bin"
cmd7Topic = 'WT/{}/{}/BackDoor'.format(dev_type,updateList[0]['sn'])
cmd7ResTopic = 'WT/{}/{}/BackDoorResp'.format(dev_type,updateList[0]['sn'])
CheckPassFlag = False
......@@ -63,6 +61,28 @@ FIXED_STAMPING_SIZE = 37
FIXED_HEAD = 3
#----------------------------------------------------------------------------------------#
def extract_characters_around(pattern, text, before=1, after=2):
matches = re.finditer(pattern, text)
for match in matches:
start = match.start()
before_chars = text[start-before-1:start] if before > 0 else ''
target_char = text[start]
after_chars = text[start+1:start+after+1] if after > 0 else ''
return before_chars+"_"+after_chars
def get_substrings_around(main_str, sub_str, before=0, after=10):
start = main_str.find(sub_str)
if start == -1:
return None, None # 子字符串未找到
# 提取前一段和后一段字符串
before_str = main_str[0:start]
after_str = main_str[start + len(sub_str):-1]
return before_str, after_str
def get_Image_Size(file_path):
file_size = 0
with open(file_path, 'rb') as file:
......@@ -144,21 +164,33 @@ def main_client_on_message(client, userdata, msg):
try:
Cmd7Res = json.loads(msg.payload)
if 'stamping' in Cmd7Res:
print("检查本地镜像")
UpdataImageStamping = read_stamping(file_path)
UpdataImageStamping = UpdataImageStamping.decode()
if UpdataImageStamping == Cmd7Res['stamping']:
print("Romote Stamping {}".format(Cmd7Res['stamping']))
print("Local Stamping {}".format(UpdataImageStamping))
print("Equal")
LocalImage = read_stamping(file_path)
LocalImage = LocalImage.decode()
local_version = extract_characters_around("_", str(LocalImage))
print("\nLocal 镜像版本:{}".format(local_version))
Local_before, Local_after = get_substrings_around(LocalImage, local_version)
RemoteImage = Cmd7Res['stamping']
RemoteImage = RemoteImage
Remote_version = extract_characters_around("_", str(RemoteImage))
print("\nRemote 镜像版本:{}".format(Remote_version))
Remote_before, Remote_after = get_substrings_around(RemoteImage, Remote_version)
if Local_before == Remote_before and Local_after == Remote_after:
CheckPassFlag = True
print("Equal")
else:
print("Romote Stamping {}".format(Cmd7Res['stamping']))
print("Local Stamping {}".format(UpdataImageStamping))
print("exit")
print(LocalImage)
print(RemoteImage)
print("Before {}|{}".format(Local_before, Remote_before))
print("After {}|{}".format(Local_after, Remote_after))
print("Fail")
except:
except Exception as e:
log("Error Cmd 7 Res")
print("Exception-> {}".format(e))
def checkVersion(oldVersion):
......@@ -261,7 +293,7 @@ def log(logData):
path = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
resourcesPath = path + os.sep + 'scripts' + os.sep
resourcesPath = path + os.sep + 'safe_Upgrade_Python_Scripts' + os.sep
curFileList = os.listdir(os.getcwd())
oldTime = time.time()
......@@ -289,7 +321,7 @@ log('packageSize: ' + str(packageSize))
if not file_path:
log('Update file has not found.')
else:
mainClient = mqtt.Client()
mainClient = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1)
mainClient.username_pw_set(mqttConfig['userName'], mqttConfig['password'])
mainClient.on_connect = main_client_on_connect
mainClient.on_message = main_client_on_message
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment