Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
E
EmbeddedDevice_SafeUpgrade
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Python_Scripts_For_Embedded_Developer
EmbeddedDevice_SafeUpgrade
Commits
8ee22668
Commit
8ee22668
authored
Jul 05, 2024
by
aohui.li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化升级的验证字段
parent
282350fa
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
338 additions
and
306 deletions
+338
-306
at32_gateway_safe_update.py
at32_gateway_safe_update.py
+338
-306
No files found.
at32_gateway_safe_update.py
View file @
8ee22668
...
...
@@ -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
=
'WTG90
2F'
dev_type
=
'WTG90
6F'
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
(
"
\n
Local 镜像版本:{}"
.
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
(
"
\n
Remote 镜像版本:{}"
.
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
+
's
cripts'
+
os
.
sep
resourcesPath
=
path
+
os
.
sep
+
's
afe_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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment