Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
upy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
pub
upy
Commits
50f6f3d8
Commit
50f6f3d8
authored
1 year ago
by
Neil Gershenfeld
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parents
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
upy.py
+79
-0
79 additions, 0 deletions
upy.py
with
79 additions
and
0 deletions
upy.py
0 → 100644
+
79
−
0
View file @
50f6f3d8
#!/usr/bin/env python3
#
# upy.py: raw REPL tool
# udp.py port ls
# udp.py port run file.py
# udp.py port put file.py
# use single quotes for triple quote strings
# udp.py port get file.py
# udp.py port rm file.py
#
# Neil Gershenfeld 6/23/23
#
# This work may be reproduced, modified, distributed,
# performed, and displayed for any purpose, but must
# acknowledge this project. Copyright is retained and
# must be preserved. The work is provided as is; no
# warranty is provided, and users accept all liability.
#
import
sys
,
serial
,
time
if
(
len
(
sys
.
argv
)
<
3
):
print
(
"
upy.py port command [arguments]
"
)
s
=
serial
.
Serial
(
sys
.
argv
[
1
])
s
.
write
(
b
'
\r\n\x03\r\n
'
)
# ^c break
s
.
write
(
b
'
\x01
'
)
# ^a enter raw mode
while
(
s
.
in_waiting
>
0
):
# clear buffer
s
.
read
()
if
(
sys
.
argv
[
2
]
==
'
run
'
):
file
=
open
(
sys
.
argv
[
3
],
'
r
'
)
str
=
file
.
read
()
file
.
close
()
for
i
in
str
:
s
.
write
(
bytes
(
i
,
'
ascii
'
))
time
.
sleep
(
0.001
)
s
.
write
(
b
'
\x04
'
)
# ^d exit raw mode and execute
while
(
True
):
# show output
sys
.
stdout
.
write
(
s
.
read
().
decode
(
'
utf-8
'
))
elif
(
sys
.
argv
[
2
]
==
'
ls
'
):
s
.
write
(
b
'
import os
\n
'
)
s
.
write
(
b
'
files = os.listdir()
\n
'
)
s
.
write
(
b
'
print(
""
)
\n
'
)
s
.
write
(
b
'
for i in files:
\n
'
)
s
.
write
(
b
'
print(i)
\n
'
)
s
.
write
(
b
'
\x04
'
)
# ^d exit raw mode and execute
time
.
sleep
(
0.1
)
while
(
s
.
in_waiting
>
0
):
# show output
sys
.
stdout
.
write
(
s
.
read
().
decode
(
'
utf-8
'
))
print
(
''
)
elif
(
sys
.
argv
[
2
]
==
'
put
'
):
file
=
open
(
sys
.
argv
[
3
],
'
r
'
)
str
=
file
.
read
()
file
.
close
()
s
.
write
(
bytes
(
f
'
str =
"""
{
str
}
"""
\n
'
,
'
ascii
'
))
s
.
write
(
bytes
(
f
'
file = open(
"
{
sys
.
argv
[
3
]
}
"
,
"
w
"
)
\n
'
,
'
ascii
'
))
s
.
write
(
b
'
file.write(str)
\n
'
)
s
.
write
(
b
'
file.close()
\n
'
)
s
.
write
(
b
'
del str
\n
'
)
s
.
write
(
b
'
\x04
'
)
# ^d exit raw mode and execute
time
.
sleep
(
0.1
)
while
(
s
.
in_waiting
>
0
):
# show output and quit
sys
.
stdout
.
write
(
s
.
read
().
decode
(
'
utf-8
'
))
print
(
''
)
elif
(
sys
.
argv
[
2
]
==
'
get
'
):
s
.
write
(
bytes
(
f
'
file = open(
"
{
sys
.
argv
[
3
]
}
"
,
"
r
"
)
\n
'
,
'
ascii
'
))
s
.
write
(
b
'
print(file.read())
\n
'
)
s
.
write
(
b
'
file.close()
\n
'
)
s
.
write
(
b
'
\x04
'
)
# ^d exit raw mode and execute
time
.
sleep
(
0.1
)
while
(
s
.
in_waiting
>
0
):
# show output and quit
sys
.
stdout
.
write
(
s
.
read
().
decode
(
'
utf-8
'
))
print
(
''
)
elif
(
sys
.
argv
[
2
]
==
'
rm
'
):
s
.
write
(
b
'
import os
\n
'
)
s
.
write
(
bytes
(
f
'
os.remove(
"
{
sys
.
argv
[
3
]
}
"
)
\n
'
,
'
ascii
'
))
s
.
write
(
b
'
\x04
'
)
# ^d exit raw mode and execute
time
.
sleep
(
0.1
)
while
(
s
.
in_waiting
>
0
):
# show output and quit
sys
.
stdout
.
write
(
s
.
read
().
decode
(
'
utf-8
'
))
print
(
''
)
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