You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/labs/IoTServices/RPi/app.py

59 lines
1.8 KiB

import os
import signal
import can
import threading
import urllib2
from subprocess import Popen, PIPE, STDOUT
def action(msg):
print 'action start'
try:
if msg.data[1] == 1:
#play(bytes(msg.data[0]))
urllib2.urlopen('http://localhost:5000/Home/Command/?command=play&args='+str(msg.data[0])).read()
if msg.data[1] == 2:
#control('p')
urllib2.urlopen('http://localhost:5000/Home/Command/?command=pause').read()
if msg.data[1] == 3:
#global player
#os.killpg(os.getpgid(player.pid), signal.SIGTERM)
urllib2.urlopen('http://localhost:5000/Home/Command/?command=stop').read()
if msg.data[2] > 0:
#control('\e\x1b[C')
urllib2.urlopen('http://localhost:5000/Home/Command/?command=si').read()
if msg.data[3] > 0:
#control('\e\x1b[D')
urllib2.urlopen('http://localhost:5000/Home/Command/?command=sd').read()
if msg.data[4] > 0:
#control('*')
urllib2.urlopen('http://localhost:5000/Home/Command/?command=vi').read()
if msg.data[5] > 0:
#control('/')
urllib2.urlopen('http://localhost:5000/Home/Command/?command=vd').read()
except Exception, e:
print 'action>repr(e):\t', repr(e)
finally:
print 'action end'
os.system('sudo ifconfig can0 down')
#os.system('sudo ip link set can0 type can bitrate 100000')
os.system('sudo ip link set can0 type can bitrate 500000')
os.system('sudo ifconfig can0 up')
can0 = can.interface.Bus(channel='can0', bustype='socketcan_ctypes')
while 1 == 1:
try:
msg = can0.recv(10.0)
if msg is not None:
print msg
if msg.arbitration_id == 0x0427 :
action(msg)
except Exception, e:
print 'repr(e):\t', repr(e)
finally:
print 'continue'
os.system('sudo ifconfig can0 down')