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.
83 lines
2.0 KiB
83 lines
2.0 KiB
import os
|
|
import signal
|
|
import can
|
|
import threading
|
|
|
|
from subprocess import Popen, PIPE, STDOUT
|
|
|
|
player = None
|
|
|
|
|
|
def play(name):
|
|
print name
|
|
file = '/root/RPi/upload/'+name+'.mp4'
|
|
#file = os.getcwd()+'/upload/'+name+'.mp4'
|
|
try:
|
|
global player
|
|
control('q')
|
|
#player = Popen(['mplayer', file],
|
|
#player = Popen(['vlc','-f', file],stdin=PIPE, preexec_fn=os.setsid)
|
|
#player = Popen(['omxplayer','-o','both', file],
|
|
player = Popen(['mplayer', '-fs', '-zoom','-vc','ffh264', file],stdin=PIPE, preexec_fn=os.setsid)
|
|
except Exception, e:
|
|
print 'play>repr(e):\t', repr(e)
|
|
finally:
|
|
print 'play>play/pause end'
|
|
|
|
|
|
def control(cmd):
|
|
print(cmd)
|
|
try:
|
|
global player
|
|
player.stdin.write(cmd)
|
|
player.stdin.flush()
|
|
except Exception, e:
|
|
print 'control>repr(e):\t', repr(e)
|
|
finally:
|
|
print cmd
|
|
|
|
|
|
def action(msg):
|
|
print 'action start'
|
|
try:
|
|
if msg.data[1] == 1:
|
|
play(bytes(msg.data[0]))
|
|
if msg.data[1] == 2:
|
|
control('p')
|
|
if msg.data[1] == 3:
|
|
global player
|
|
os.killpg(os.getpgid(player.pid), signal.SIGTERM)
|
|
# control('q')
|
|
# player.kill()
|
|
#os.write('killall mplayer')
|
|
if msg.data[2] > 0:
|
|
control('\e\x1b[C')
|
|
if msg.data[3] > 0:
|
|
control('\e\x1b[D')
|
|
if msg.data[4] > 0:
|
|
control('*')
|
|
if msg.data[5] > 0:
|
|
control('/')
|
|
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 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
|
|
action(msg)
|
|
except Exception, e:
|
|
print 'repr(e):\t', repr(e)
|
|
finally:
|
|
print 'continue'
|
|
|
|
os.system('sudo ifconfig can0 down')
|