Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Software
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Environments
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
LARN
RNA
Software
Commits
64f39612
Commit
64f39612
authored
Jul 26, 2019
by
Marlene Böhmer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extended Test
parent
947ef15a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
9 deletions
+20
-9
salt/drone/scripts/uart_test.py
salt/drone/scripts/uart_test.py
+20
-9
No files found.
salt/drone/scripts/uart_test.py
View file @
64f39612
...
...
@@ -5,15 +5,22 @@ import serial
MTU
=
32
START_BYTE1
=
0xbc
START_BYTE2
=
0xcf
S
TART
=
[
START_BYTE1
,
START_BYTE2
]
S
YSLINK_RADIO_RAW
=
0x00
received_data
=
[]
ser
=
serial
.
Serial
(
"/dev/ttyS0"
,
115200
)
def
compute_cksum
(
list
):
cksum0
,
cksum1
=
0
,
0
for
i
in
list
:
cksum0
=
(
cksum0
+
i
)
&
0xff
cksum1
=
(
cksum1
+
cksum0
)
&
0xff
return
[
cksum0
,
cksum1
]
while
True
:
received_data
=
map
(
ord
,
list
(
ser
.
read_until
(
chr
(
START_BYTE1
))))
received_data
=
map
(
ord
,
list
(
ser
.
read_until
(
chr
(
START_BYTE1
)))
[
-
1
:]
)
received_data
+=
map
(
ord
,
list
(
ser
.
read
(
1
)))
if
received_data
[
1
]
!=
START_BYTE2
:
print
(
"ERROR START"
)
...
...
@@ -25,16 +32,20 @@ while True:
continue
received_data
+=
map
(
ord
,
list
(
ser
.
read
(
received_data
[
3
]
+
2
)))
cksum0
=
0
cksum1
=
0
for
c
in
received_data
[
2
:
-
2
]:
cksum0
=
(
cksum0
+
c
)
&
0xff
cksum1
=
(
cksum1
+
cksum0
)
&
0xff
if
cksum0
!=
received_data
[
-
2
]
or
cksum1
!=
received_data
[
-
1
]:
cksum
=
compute_cksum
(
received_data
[
2
:
-
2
])
if
cksum
[
0
]
!=
received_data
[
-
2
]
or
cksum
[
1
]
!=
received_data
[
-
1
]:
print
(
"ERROR CKSUM"
)
continue
print
(
" "
.
join
(
"{:#04x}"
.
format
(
n
)
for
n
in
received_data
))
out_data
=
[
1
,
2
]
pk
=
[
1
,
2
]
header
=
[
SYSLINK_RADIO_RAW
,
len
(
pk
)]
out_data
=
[
START_BYTE1
,
START_BYTE2
]
out_data
+=
header
out_data
+=
pk
out_data
+=
compute_cksum
(
header
+
pk
)
written
=
ser
.
write
(
bytearray
(
out_data
))
print
(
written
)
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