Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
Lego_Robots
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Matthew Baxter
Lego_Robots
Commits
7c9247e1
Commit
7c9247e1
authored
Jun 29, 2015
by
Carl Hetherington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial.
parents
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
0 deletions
+105
-0
.gitignore
.gitignore
+1
-0
listen.py
listen.py
+34
-0
snap-ev3.py
snap-ev3.py
+41
-0
snap-ev3.xml
snap-ev3.xml
+29
-0
No files found.
.gitignore
0 → 100644
View file @
7c9247e1
*~
listen.py
0 → 100644
View file @
7c9247e1
import
SimpleHTTPServer
import
SocketServer
import
socket
import
os
import
sys
from
ev3.lego
import
MediumMotor
if
len
(
sys
.
argv
)
!=
2
:
print
>>
sys
.
stderr
,
'Syntax:
%
s <port>'
%
(
sys
.
argv
[
0
])
sys
.
exit
(
1
)
class
Handler
(
SimpleHTTPServer
.
SimpleHTTPRequestHandler
):
def
do_GET
(
self
):
parts
=
self
.
path
[
1
:]
.
split
(
'/'
)
print
parts
if
len
(
parts
)
==
4
and
parts
[
0
]
==
'motor'
:
print
'Run
%
s to
%
s at speed
%
s'
%
(
parts
[
1
],
parts
[
2
],
parts
[
3
])
d
=
MediumMotor
(
parts
[
1
])
d
.
run_position_limited
(
int
(
parts
[
2
]),
int
(
parts
[
3
]),
absolute
=
False
)
self
.
send_response
(
200
)
self
.
send_header
(
'Content-Type'
,
'text/html'
)
self
.
end_headers
()
self
.
wfile
.
write
(
'OK'
)
self
.
wfile
.
close
()
class
TCPServer
(
SocketServer
.
TCPServer
):
def
server_bind
(
self
):
self
.
socket
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
self
.
socket
.
bind
(
self
.
server_address
)
httpd
=
TCPServer
((
""
,
int
(
sys
.
argv
[
1
])),
Handler
)
print
'EV3 ready.'
httpd
.
serve_forever
()
snap-ev3.py
0 → 100644
View file @
7c9247e1
import
SimpleHTTPServer
import
SocketServer
import
socket
import
os
import
urllib2
# Port to listen to Snap on
SNAP_PORT
=
1330
# Port for EV3 to listen on
EV3_PORT
=
8192
# EV3 user ID and IP address
EV3_CONNECTION
=
'root@10.42.0.51'
class
Handler
(
SimpleHTTPServer
.
SimpleHTTPRequestHandler
):
def
send_head
(
self
):
if
self
.
path
==
'/snap-ev3'
:
f
=
open
(
'snap-ev3.xml'
,
'rb'
)
self
.
send_response
(
200
)
self
.
send_header
(
"Content-type"
,
'text/xml'
)
fs
=
os
.
fstat
(
f
.
fileno
())
self
.
send_header
(
"Content-Length"
,
str
(
fs
[
6
]))
self
.
send_header
(
"Last-Modified"
,
self
.
date_time_string
(
fs
.
st_mtime
))
self
.
send_header
(
"Access-Control-Allow-Origin"
,
"*"
)
self
.
end_headers
()
return
f
else
:
SimpleHTTPServer
.
SimpleHTTPRequestHandler
.
send_head
(
self
)
urllib2
.
urlopen
(
"http://10.42.0.51:
%
d
%
s"
%
(
EV3_PORT
,
self
.
path
),
timeout
=
5
)
.
read
()
class
TCPServer
(
SocketServer
.
TCPServer
):
def
server_bind
(
self
):
self
.
socket
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
self
.
socket
.
bind
(
self
.
server_address
)
print
"Starting listener on EV3"
os
.
system
(
'scp listen.py
%
s:'
%
EV3_CONNECTION
)
os
.
system
(
'ssh
%
s -- nohup python listen.py
%
d &'
%
(
EV3_CONNECTION
,
EV3_PORT
))
httpd
=
TCPServer
((
""
,
SNAP_PORT
),
Handler
)
print
"http://snap.berkeley.edu/snapsource/snap.html#open:http://localhost:1330/snap-ev3"
httpd
.
serve_forever
()
snap-ev3.xml
0 → 100644
View file @
7c9247e1
<blocks
app=
"Snap! 4.0, http://snap.berkeley.edu"
version=
"1"
>
<block-definition
category=
"control"
s=
"move motor %'motor' %'degrees' degrees at %'speed' speed"
type=
"command"
>
<inputs>
<input
type=
"%txt"
>
a
</input>
<input
type=
"%n"
>
360
</input>
<input
type=
"%n"
>
100
</input>
</inputs>
<script>
<block
s=
"doRun"
>
<block
s=
"reifyReporter"
>
<autolambda>
<block
s=
"reportURL"
>
<block
s=
"reportJoinWords"
>
<list>
<l>
localhost:1330/motor/
</l>
<block
var=
"motor"
/>
<l>
/
</l>
<block
var=
"degrees"
/>
<l>
/
</l>
<block
var=
"speed"
/>
</list>
</block>
</block>
</autolambda>
</block>
</block>
</script>
</block-definition>
</blocks>
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