-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjiraya.py
executable file
·110 lines (85 loc) · 2.63 KB
/
jiraya.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/python
# -*- coding: utf-8 -*-
import colorama
from colorama import Fore, Back
import shlex
import signal
import readline
import os, sys
folder = os.path.dirname(os.path.abspath(__file__)) + "/lib/"
sys.path.append(folder)
import msr605_cmd
import msr605_drv
import time
import optparse
def optionsManager():
parser = optparse.OptionParser(sys.argv[0]+" --help")
parser.add_option('-d','--dev',dest="DEV",type="string",help='/dev/ttyUSB0')
parser.add_option('-t','--type',dest="TYPE",type="string",help='<iso,raw>')
parser.add_option('-m','--mode',dest="MODE",type="string",help='<hico,loco>')
parser.add_option('-c','--cmd',dest="CMD",type="string",help='<read,write,...>')
(opt, args) = parser.parse_args()
return opt
global Save, autoSave, bpc, bpi, mode, track_type, dev_ptr, tty
options = optionsManager()
Save = ""
autoSave = False
bpc = ['8', '8', '8'] # bits per character for each tracks
bpi = ['210', '75', '210'] # bits per inch for each tracks
if options.MODE is not None:
mode = options.MODE
else:
mode = 'hico'
if options.TYPE is not None:
track_type = options.TYPE
else:
track_type = 'iso'
if options.DEV is not None:
tty = options.DEV
else:
tty = "/dev/ttyUSB0"
def tokenize(string):
"""
to get a well formed command+args
"""
return shlex.split(string)
def shell_loop(device,init_cmd):
# auto-completion
readline.set_completer(msr605_cmd.completer)
readline.parse_and_bind('tab: complete')
dev_ptr = msr605_drv.msr_init(device)
if dev_ptr == False:
print " [-] Please check that the device is on /dev/ttyUSB0"
sys.exit(1)
# init
msr605_drv.msr_reset(dev_ptr)
msr605_drv.set_coercivity(mode,dev_ptr)
msr605_drv.set_bpc(int(bpc[0]), int(bpc[1]), int(bpc[2]),dev_ptr)
c = True
while c:
if init_cmd is None:
# display a command prompt
cmd = raw_input(Back.WHITE+Fore.RED+' msr605 ['+device+'](help/settings)> '+Back.RESET+Fore.CYAN+' ')
else:
cmd = init_cmd
# tokenize the command input
cmd_tokens = tokenize(cmd)
# execute the command
msr605_cmd.execute(cmd_tokens, dev_ptr)
if init_cmd is not None:
c = False
def closeProgram(signal, frame):
sys.exit(1)
def main():
signal.signal(signal.SIGINT, closeProgram) # close program with Ctrl+C
if options.DEV is not None:
device = options.DEV
else:
device = "/dev/ttyUSB0"
if options.CMD is not None:
init_cmd = options.CMD
else:
init_cmd = None
shell_loop(device, init_cmd)
if __name__ == '__main__':
main()