Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lwc
/
compare
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
84bd336c
authored
Jul 10, 2019
by
Sebastian Renner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Encoding is fun!
parent
26b36a28
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
8 deletions
+9
-8
templates/blackpill/middleware.py
+7
-6
test.py
+2
-2
No files found.
templates/blackpill/middleware.py
View file @
84bd336c
...
@@ -6,6 +6,8 @@ import struct
...
@@ -6,6 +6,8 @@ import struct
import
serial
import
serial
from
subprocess
import
Popen
,
PIPE
,
run
from
subprocess
import
Popen
,
PIPE
,
run
ser
=
serial
.
Serial
(
'/dev/ttyUSB0'
,
115200
)
def
flash
():
def
flash
():
run
(
"JLinkExe flash.jlink"
,
shell
=
True
,
check
=
True
)
run
(
"JLinkExe flash.jlink"
,
shell
=
True
,
check
=
True
)
...
@@ -20,7 +22,7 @@ def read(channel, l):
...
@@ -20,7 +22,7 @@ def read(channel, l):
raise
Exception
(
"could not read
%
d bytes of data (got
%
d)"
%
(
l
,
len
(
data
)))
raise
Exception
(
"could not read
%
d bytes of data (got
%
d)"
%
(
l
,
len
(
data
)))
return
data
return
data
def
write
(
channel
,
data
,
direction
):
def
write
(
channel
,
data
):
if
channel
==
'ser'
:
if
channel
==
'ser'
:
l
=
ser
.
write
(
data
)
l
=
ser
.
write
(
data
)
elif
channel
==
'std'
:
elif
channel
==
'std'
:
...
@@ -32,18 +34,17 @@ def write(channel, data, direction):
...
@@ -32,18 +34,17 @@ def write(channel, data, direction):
def
obtain
(
channel
):
def
obtain
(
channel
):
l
=
read
(
channel
,
4
)
l
=
read
(
channel
,
4
)
print
(
l
)
l
=
str
.
encode
(
l
)
(
l
,
)
=
struct
.
unpack
(
"<I"
,
l
)
(
l
,
)
=
struct
.
unpack
(
"<I"
,
l
)
return
read
(
channel
,
l
)
return
read
(
channel
,
l
)
def
submit
(
channel
,
action
,
data
):
def
submit
(
channel
,
action
,
data
):
h
=
struct
.
pack
(
"<BI"
,
ord
(
action
),
len
(
data
))
h
=
struct
.
pack
(
"<BI"
,
ord
(
action
),
len
(
data
))
write
(
channel
,
h
)
write
(
channel
,
h
)
write
(
channel
,
data
)
write
(
channel
,
str
.
encode
(
data
)
)
def
main
():
def
main
():
#flash()
#flash()
ser
=
serial
.
Serial
(
'/dev/ttyUSB0'
,
115200
)
while
(
1
):
while
(
1
):
action
=
read
(
'std'
,
1
)
action
=
read
(
'std'
,
1
)
if
(
action
):
if
(
action
):
...
@@ -52,10 +53,10 @@ def main():
...
@@ -52,10 +53,10 @@ def main():
submit
(
'ser'
,
action
,
data
)
submit
(
'ser'
,
action
,
data
)
elif
action
==
'e'
or
action
==
'd'
:
elif
action
==
'e'
or
action
==
'd'
:
write
(
'ser'
,
action
)
write
(
'ser'
,
str
.
encode
(
action
)
)
elif
action
==
'C'
or
action
==
'M'
or
action
==
'A'
or
action
==
'K'
or
action
==
'S'
or
action
==
'P'
:
elif
action
==
'C'
or
action
==
'M'
or
action
==
'A'
or
action
==
'K'
or
action
==
'S'
or
action
==
'P'
:
write
(
'ser'
,
action
)
write
(
'ser'
,
str
.
encode
(
action
)
)
data
=
obtain
(
'ser'
)
data
=
obtain
(
'ser'
)
submit
(
'std'
,
action
,
data
)
submit
(
'std'
,
action
,
data
)
else
:
else
:
...
...
test.py
View file @
84bd336c
...
@@ -37,8 +37,8 @@ def main(argv):
...
@@ -37,8 +37,8 @@ def main(argv):
(
l
,
)
=
struct
.
unpack
(
"<I"
,
l
)
(
l
,
)
=
struct
.
unpack
(
"<I"
,
l
)
return
read
(
l
)
return
read
(
l
)
if
read
(
14
)
!=
b
"Hello, World!
\n
"
:
#
if read(14) != b"Hello, World!\n":
raise
Exception
(
"Unexpected output"
)
#
raise Exception("Unexpected output")
m
=
b
""
m
=
b
""
ad
=
b
""
ad
=
b
""
...
...
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