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
864c7749
authored
Jul 12, 2019
by
Sebastian Renner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Debug to stderr if necessary
parent
520bc41f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
9 deletions
+14
-9
subprocess.log
+0
-0
templates/blackpill/middleware.py
+14
-9
No files found.
subprocess.log
deleted
100644 → 0
View file @
520bc41f
This diff is collapsed.
Click to expand it.
templates/blackpill/middleware.py
View file @
864c7749
...
...
@@ -7,7 +7,8 @@ import struct
import
serial
import
subprocess
f
=
open
(
"subprocess.log"
,
"w+"
)
DBG
=
'1'
ser
=
serial
.
Serial
(
'/dev/ttyUSB0'
,
115200
)
...
...
@@ -23,8 +24,6 @@ def read(channel, l):
data
=
sys
.
stdin
.
buffer
.
read
(
l
)
else
:
raise
Exception
(
"read() complains: no sai channelino"
)
# if channel == "std" and len(data) == 0:
# sys.exit(0)
if
len
(
data
)
!=
l
:
raise
Exception
(
"could not read
%
d bytes of data (got
%
d)"
%
(
l
,
len
(
data
)))
return
data
...
...
@@ -32,7 +31,8 @@ def read(channel, l):
def
write
(
channel
,
data
):
if
channel
==
'ser'
:
l
=
ser
.
write
(
data
)
f
.
write
(
"Data sent to serial: "
+
str
(
data
)
+
"
\n
"
)
if
DBG
:
print
(
"Data sent to serial: "
+
str
(
data
)
+
"
\n
"
,
file
=
sys
.
stderr
)
elif
channel
==
'std'
:
l
=
sys
.
stdout
.
buffer
.
write
(
data
)
else
:
...
...
@@ -43,7 +43,8 @@ def write(channel, data):
def
obtain
(
channel
):
l
=
read
(
channel
,
4
)
(
l
,
)
=
struct
.
unpack
(
"<I"
,
l
)
f
.
write
(
"Trying to read
%
d bytes from
%
s
\n
"
%
(
l
,
channel
))
if
DBG
:
print
(
"Trying to read
%
d bytes from
%
s
\n
"
%
(
l
,
channel
),
file
=
sys
.
stderr
)
return
read
(
channel
,
l
)
def
submit
(
channel
,
action
,
data
):
...
...
@@ -56,15 +57,17 @@ def submit(channel, action, data):
time
.
sleep
(
0.1
)
def
main
(
argv
):
if
DBG
:
print
(
argv
[
0
],
file
=
sys
.
stderr
)
script_dir
=
os
.
path
.
split
(
argv
[
0
])[
0
]
if
len
(
script_dir
)
>
0
:
os
.
chdir
(
script_dir
)
f
.
write
(
os
.
getcwd
())
flash
()
print
(
"Hello, World!"
)
while
(
1
):
action
=
read
(
'std'
,
1
)
f
.
write
(
"Read following action from stdin:
%
s
\n
"
%
action
)
if
DBG
:
print
(
"Read following action from stdin:
%
s
\n
"
%
action
,
file
=
sys
.
stderr
)
if
action
==
b
'c'
or
action
==
b
'm'
or
action
==
b
'a'
or
action
==
b
'k'
or
action
==
b
's'
or
action
==
b
'p'
:
data
=
obtain
(
'std'
)
submit
(
'ser'
,
action
,
data
)
...
...
@@ -75,9 +78,11 @@ def main(argv):
elif
action
==
b
'C'
or
action
==
b
'M'
or
action
==
b
'A'
or
action
==
b
'K'
or
action
==
b
'S'
or
action
==
b
'P'
:
write
(
'ser'
,
action
)
data
=
obtain
(
'ser'
)
f
.
write
(
"Obtained following data from serial:
%
s
\n
"
%
data
)
if
DBG
:
print
(
"Obtained following data from serial:
%
s
\n
"
%
data
,
file
=
sys
.
stderr
)
submit
(
'std'
,
action
,
data
)
f
.
write
(
"Submitted following data to stdout:
%
s
\n
"
%
data
)
if
DBG
:
print
(
"Submitted following data to stdout:
%
s
\n
"
%
data
,
file
=
sys
.
stderr
)
else
:
raise
Exception
(
"no capiche aczione
%
s"
%
(
action
))
...
...
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