-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptRun.py
More file actions
81 lines (64 loc) · 2.02 KB
/
ScriptRun.py
File metadata and controls
81 lines (64 loc) · 2.02 KB
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
from datetime import datetime
class DataProcesser(object):
"""docstring for DataProcesser"""
def __init__(self):
self.record_file = None
# function
self.methodlist = {}
self.methodlist['help'] = self.on_help
self.methodlist['startRec'] = self.on_startRec
self.methodlist['stopRec'] = self.on_stopRec
self.methodlist['screen'] = self.on_screen
self.methodlist['getcommands'] = self.on_getcommands
def process(self, data):
# print('DataProcesser:', data)
bin_spos = data.find('"bin":')
bin_data = None
if bin_spos != -1:
# have binary data
bin_epos= data.find('}--end--')
bin_data = data[bin_spos+6:bin_epos]
data = data[:bin_spos-1] + '}'
dictdata = eval(data)
method = dictdata['method']
param = dictdata['param']
print('type:',type(method),type(param))
return (method,self.methodlist[method](param,bin_data))
def issupport(self, name):
for i in self.methodlist:
if i == name and self.methodlist[i] != None:
return True
return False
def on_help(self, list_data,bin_data):
result = 'Support Command: '
for i in range(len(list_data)):
result += '%s ' % list_data[i]
if i == 6 or i == 13 or i == 20:
result += '\n'
result += '\n'
return result
def on_getcommands(self,list_data,bin_data):
return list_data
def set_recfilename(self, filename):
self.record_file = open(filename,'w')
print('create file:',self.record_file)
def on_startRec(self, list_data,bin_data):
result = ''
for i in list_data:
result += '%s\n' % i
if self.record_file != None:
self.record_file.write(result)
return result
def on_stopRec(self, list_data,bin_data):
print 'close file '
self.record_file.close()
self.record_file = None
return 'Stop Record'
def on_screen(self, list_data,bin_data):
now = datetime.today()
# print 'bin_data:',bin_data
filename = "%s-%s-%s.bmp" % (now.hour,now.minute,now.second)
f = open(filename,'wb')
f.write(bin_data)
f.close()
return "save file:%s,size:%d" % (filename,len(bin_data))