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

优化升级的验证字段

parent 282350fa
...@@ -9,8 +9,7 @@ import os ...@@ -9,8 +9,7 @@ import os
import threading import threading
import json import json
import time import time
import sys import re
import zlib
#----------------------------------------------------------------------------------------# #----------------------------------------------------------------------------------------#
# 测试平台 # 测试平台
...@@ -39,7 +38,7 @@ mqttConfig = { ...@@ -39,7 +38,7 @@ mqttConfig = {
# } # }
dev_type = 'WTG902F' dev_type = 'WTG906F'
updateCheckInTopic = 'WT/%s/Update/CheckIn' % dev_type updateCheckInTopic = 'WT/%s/Update/CheckIn' % dev_type
updateResponseTopic = 'WT/%s/Update/Response' % dev_type updateResponseTopic = 'WT/%s/Update/Response' % dev_type
...@@ -48,11 +47,10 @@ updateTopic = 'WT/%s/{0}/Update' % dev_type ...@@ -48,11 +47,10 @@ updateTopic = 'WT/%s/{0}/Update' % dev_type
updateList = [{'sn': '21126112', 'package': 0, 'time': time.time(), 'send': True}] 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']) cmd7Topic = 'WT/{}/{}/BackDoor'.format(dev_type,updateList[0]['sn'])
cmd7ResTopic = 'WT/{}/{}/BackDoorResp'.format(dev_type,updateList[0]['sn']) cmd7ResTopic = 'WT/{}/{}/BackDoorResp'.format(dev_type,updateList[0]['sn'])
CheckPassFlag = False CheckPassFlag = False
...@@ -63,6 +61,28 @@ FIXED_STAMPING_SIZE = 37 ...@@ -63,6 +61,28 @@ FIXED_STAMPING_SIZE = 37
FIXED_HEAD = 3 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): def get_Image_Size(file_path):
file_size = 0 file_size = 0
with open(file_path, 'rb') as file: with open(file_path, 'rb') as file:
...@@ -144,21 +164,33 @@ def main_client_on_message(client, userdata, msg): ...@@ -144,21 +164,33 @@ def main_client_on_message(client, userdata, msg):
try: try:
Cmd7Res = json.loads(msg.payload) Cmd7Res = json.loads(msg.payload)
if 'stamping' in Cmd7Res: if 'stamping' in Cmd7Res:
print("检查本地镜像") LocalImage = read_stamping(file_path)
UpdataImageStamping = read_stamping(file_path) LocalImage = LocalImage.decode()
UpdataImageStamping = UpdataImageStamping.decode() local_version = extract_characters_around("_", str(LocalImage))
if UpdataImageStamping == Cmd7Res['stamping']: print("\nLocal 镜像版本:{}".format(local_version))
print("Romote Stamping {}".format(Cmd7Res['stamping'])) Local_before, Local_after = get_substrings_around(LocalImage, local_version)
print("Local Stamping {}".format(UpdataImageStamping))
print("Equal")
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 CheckPassFlag = True
print("Equal")
else: else:
print("Romote Stamping {}".format(Cmd7Res['stamping'])) print(LocalImage)
print("Local Stamping {}".format(UpdataImageStamping)) print(RemoteImage)
print("exit") 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") log("Error Cmd 7 Res")
print("Exception-> {}".format(e))
def checkVersion(oldVersion): def checkVersion(oldVersion):
...@@ -261,7 +293,7 @@ def log(logData): ...@@ -261,7 +293,7 @@ def log(logData):
path = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) 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()) curFileList = os.listdir(os.getcwd())
oldTime = time.time() oldTime = time.time()
...@@ -289,7 +321,7 @@ log('packageSize: ' + str(packageSize)) ...@@ -289,7 +321,7 @@ log('packageSize: ' + str(packageSize))
if not file_path: if not file_path:
log('Update file has not found.') log('Update file has not found.')
else: else:
mainClient = mqtt.Client() mainClient = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1)
mainClient.username_pw_set(mqttConfig['userName'], mqttConfig['password']) mainClient.username_pw_set(mqttConfig['userName'], mqttConfig['password'])
mainClient.on_connect = main_client_on_connect mainClient.on_connect = main_client_on_connect
mainClient.on_message = main_client_on_message 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