-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathshell.py
77 lines (56 loc) · 2.04 KB
/
shell.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import sys
from lytroctrl import transactions
from lytroctrl import connections
from lytroctrl import utils
import re
import signal
from threading import Thread
import time
import os
import argparse
def signal_handler(sig, frame):
os._exit(0)
def filter_output(o):
blue_marker = "\x1b[34m"
white_marker = "\x1b[m"
output = re.sub("\x1b\[34m.*?\x1b\[m",'',o,flags=re.DOTALL) # filter blue
output = re.sub('\[\d{8}\.\d{6}\] ','',output) #filter time
return output
def shell(con,verbose=False):
r = re.compile('\[m\[\d{8}\.\d{6}\]')
while True:
output = transactions.SyncUartTransact(con).transact()
if not verbose:
output = filter_output(output)
print(output)
cmd_line = input(">")
transactions.ExecTransact(con,cmd_line).transact()
def main():
parser = argparse.ArgumentParser(description='Lytro control shell')
parser.add_argument('-v', '--verbose',
action='store_true',help="output includes debug logs")
parser.add_argument('-a','--address',
action="store",help="ip address",default="10.100.1.1")
parser.add_argument('-p','--port',
action="store",help="destination port",default="5678")
parser.add_argument('-l','--no-unlock',help="don't perform unlocking",action="store_true")
parser.add_argument('-s','--no-keepalive',help="don't start keepalive connection (camera will sleep due to inactivity)",action="store_true")
args = parser.parse_args()
con = connections.TcpConnection(args.address,int(args.port))
con.connect()
if not args.no_unlock:
tr = transactions.GetCameraInfoTransact(con)
ci = tr.transact()
camera_serial = ci.serial_num
transactions.UnlockTransact(con,camera_serial).unlock()
if not args.no_keepalive:
t = Thread(target=utils.keep_alive, args=[con])
t.start()
#transactions.CmdManual(con).transact()
shell(con,args.verbose)
#SyncUartTransact(con).transact()
#transactions.ExecTransact(con,"rfiidle 0").transact()
#transactions.UDPLiveView(con).transact(enable=True,cratio=5)
if __name__ == '__main__':
signal.signal(signal.SIGINT, signal_handler)
main()