Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MicroCART
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Distributed Autonomous Networked Control Lab
MicroCART
Commits
e6f825e4
Commit
e6f825e4
authored
8 years ago
by
dawehr
Browse files
Options
Downloads
Patches
Plain Diff
Added verification of quad checksum to test script
parent
c1614c5c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
quad/scripts/stress_tests.py
+26
-5
26 additions, 5 deletions
quad/scripts/stress_tests.py
with
26 additions
and
5 deletions
quad/scripts/stress_tests.py
+
26
−
5
View file @
e6f825e4
...
...
@@ -24,19 +24,23 @@ def create_test_packet(size=8):
data
=
bytes
((
i
%
256
for
i
in
range
(
size
)))
return
create_msg
(
0
,
1
,
0
,
data
)
def
read_packet
(
ser
):
def
read_packet
(
ser
,
raw
=
False
):
header
=
ser
.
read
(
7
)
length
=
int
.
from_bytes
(
header
[
5
:
7
],
byteorder
=
'
little
'
)
data
=
ser
.
read
(
length
)
checksum
=
ser
.
read
()
return
data
print
(
checksum
)
if
raw
:
return
header
+
data
+
checksum
else
:
return
data
def
query_received
(
ser
):
# Send request
query_msg
=
create_msg
(
0
,
2
,
0
,
b
''
)
ser
.
write
(
query_msg
)
ser
.
flush
()
sleep
(
0.1
)
resp
=
read_packet
(
ser
)
received_str
=
resp
[:
-
1
].
decode
(
'
ascii
'
)
if
len
(
received_str
)
==
0
:
...
...
@@ -55,6 +59,24 @@ def check_test(ser, n_sent, size_sent, old_status):
valid
=
False
return
valid
,
(
new_n
,
new_size
)
def
test_checksum
(
ser
):
print
(
"
Checking if received checksum is valid
"
)
# Send query packet
ser
.
write
(
create_msg
(
0
,
2
,
0
,
b
''
))
raw_data
=
read_packet
(
ser
,
True
)
print
(
"
Raw:
"
)
print
(
raw_data
.
hex
())
given_checksum
=
raw_data
[
-
1
]
computed_checksum
=
0
for
i
in
range
(
len
(
raw_data
)
-
1
):
computed_checksum
^=
raw_data
[
i
]
valid
=
computed_checksum
==
given_checksum
ret_status
=
query_received
(
ser
)
if
not
valid
:
print
(
"
Failure: Received checksum
"
+
str
(
given_checksum
)
+
"
, expected
"
+
str
(
computed_checksum
))
return
valid
,
ret_status
def
test_partial_packet
(
ser
,
cur_status
,
size
=
50
):
print
(
"
Checking partial packet...
"
)
to_send
=
create_test_packet
(
size
)
...
...
@@ -66,8 +88,6 @@ def test_partial_packet(ser, cur_status, size=50):
sleep
(
0.2
)
return
check_test
(
ser
,
1
,
size
,
cur_status
)
return
success
,
(
n_received
,
tot_size_received
)
def
test_blast
(
ser
,
cur_status
,
N
=
50
,
size
=
32
):
print
(
"
Checking data blast... of size
"
+
str
(
N
)
+
"
with size
"
+
str
(
size
))
to_send
=
create_test_packet
(
size
)
...
...
@@ -98,4 +118,5 @@ if __name__ == '__main__':
passed
,
status
=
test_blast
(
ser
,
status
)
passed
,
status
=
test_blast
(
ser
,
status
,
150
,
80
)
passed
,
status
=
test_bad_checksum
(
ser
,
status
)
passed
,
status
=
test_checksum
(
ser
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment