@@ -0,0 +1,137 | |||||
|
1 | import threading | |||
|
2 | ||||
|
3 | from PyQt4 import QtCore | |||
|
4 | from PyQt4.QtCore import SIGNAL | |||
|
5 | ||||
|
6 | from schainpy.controller import Project | |||
|
7 | ||||
|
8 | class ControllerThread(threading.Thread, Project): | |||
|
9 | ||||
|
10 | def __init__(self, filename): | |||
|
11 | ||||
|
12 | threading.Thread.__init__(self) | |||
|
13 | Project.__init__(self) | |||
|
14 | ||||
|
15 | self.setDaemon(True) | |||
|
16 | ||||
|
17 | self.filename = filename | |||
|
18 | self.control = {'stop':False, 'pause':False} | |||
|
19 | ||||
|
20 | def __del__(self): | |||
|
21 | ||||
|
22 | self.control['stop'] = True | |||
|
23 | # self.pause(1) | |||
|
24 | # self.wait() | |||
|
25 | ||||
|
26 | def stop(self): | |||
|
27 | self.control['stop'] = True | |||
|
28 | ||||
|
29 | def pause(self): | |||
|
30 | self.control['pause'] = not(self.control['pause']) | |||
|
31 | ||||
|
32 | def __run(self): | |||
|
33 | ||||
|
34 | ||||
|
35 | print "*"*40 | |||
|
36 | print " Starting SIGNAL CHAIN PROCESSING " | |||
|
37 | print "*"*40 | |||
|
38 | ||||
|
39 | ||||
|
40 | keyList = self.procUnitConfObjDict.keys() | |||
|
41 | keyList.sort() | |||
|
42 | ||||
|
43 | while(True): | |||
|
44 | ||||
|
45 | finalSts = False | |||
|
46 | #executed proc units | |||
|
47 | procUnitExecutedList = [] | |||
|
48 | ||||
|
49 | for procKey in keyList: | |||
|
50 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) | |||
|
51 | ||||
|
52 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |||
|
53 | ||||
|
54 | inputId = procUnitConfObj.getInputId() | |||
|
55 | ||||
|
56 | sts = procUnitConfObj.run() | |||
|
57 | finalSts = finalSts or sts | |||
|
58 | ||||
|
59 | procUnitExecutedList.append(procUnitConfObj.id) | |||
|
60 | ||||
|
61 | #If every process unit finished so end process | |||
|
62 | if not(finalSts): | |||
|
63 | print "Every process unit have finished" | |||
|
64 | break | |||
|
65 | ||||
|
66 | if self.control['pause']: | |||
|
67 | print "Process suspended" | |||
|
68 | ||||
|
69 | while True: | |||
|
70 | sleep(0.1) | |||
|
71 | ||||
|
72 | if not self.control['pause']: | |||
|
73 | break | |||
|
74 | ||||
|
75 | if self.control['stop']: | |||
|
76 | break | |||
|
77 | print "Process reinitialized" | |||
|
78 | ||||
|
79 | if self.control['stop']: | |||
|
80 | # print "Process stopped" | |||
|
81 | break | |||
|
82 | ||||
|
83 | #Closing every process | |||
|
84 | for procKey in keyList: | |||
|
85 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |||
|
86 | procUnitConfObj.close() | |||
|
87 | ||||
|
88 | print "Process finished" | |||
|
89 | ||||
|
90 | def run(self): | |||
|
91 | self.control['stop'] = False | |||
|
92 | self.control['pause'] = False | |||
|
93 | ||||
|
94 | self.readXml(self.filename) | |||
|
95 | self.createObjects() | |||
|
96 | self.connectObjects() | |||
|
97 | Project.run(self) | |||
|
98 | ||||
|
99 | def isRunning(self): | |||
|
100 | ||||
|
101 | return self.is_alive() | |||
|
102 | ||||
|
103 | def isFinished(self): | |||
|
104 | ||||
|
105 | return not self.is_alive() | |||
|
106 | ||||
|
107 | class ControllerQThread(QtCore.QThread, Project): | |||
|
108 | ||||
|
109 | def __init__(self, filename): | |||
|
110 | ||||
|
111 | QtCore.QThread.__init__(self) | |||
|
112 | Project.__init__(self) | |||
|
113 | ||||
|
114 | self.filename = filename | |||
|
115 | self.control = {'stop':False, 'pause':False} | |||
|
116 | ||||
|
117 | def __del__(self): | |||
|
118 | ||||
|
119 | self.control['stop'] = True | |||
|
120 | self.wait() | |||
|
121 | ||||
|
122 | def stop(self): | |||
|
123 | self.control['stop'] = True | |||
|
124 | ||||
|
125 | def pause(self): | |||
|
126 | self.control['pause'] = not(self.control['pause']) | |||
|
127 | ||||
|
128 | def run(self): | |||
|
129 | self.control['stop'] = False | |||
|
130 | self.control['pause'] = False | |||
|
131 | ||||
|
132 | self.readXml(self.filename) | |||
|
133 | self.createObjects() | |||
|
134 | self.connectObjects() | |||
|
135 | self.emit( SIGNAL( "jobStarted( PyQt_PyObject )" ), 1) | |||
|
136 | Project.run(self) | |||
|
137 | self.emit( SIGNAL( "jobFinished( PyQt_PyObject )" ), 1) No newline at end of file |
@@ -6,7 +6,6 from xml.etree.ElementTree import Element, SubElement | |||||
6 | from xml.etree import ElementTree as ET |
|
6 | from xml.etree import ElementTree as ET | |
7 | from xml.dom import minidom |
|
7 | from xml.dom import minidom | |
8 |
|
8 | |||
9 | #import datetime |
|
|||
10 | from model import * |
|
9 | from model import * | |
11 |
|
10 | |||
12 | try: |
|
11 | try: | |
@@ -888,9 +887,6 class Project(): | |||||
888 | projectElement.set('id', str(self.id)) |
|
887 | projectElement.set('id', str(self.id)) | |
889 | projectElement.set('name', self.name) |
|
888 | projectElement.set('name', self.name) | |
890 | projectElement.set('description', self.description) |
|
889 | projectElement.set('description', self.description) | |
891 |
|
||||
892 | # for readUnitConfObj in self.readUnitConfObjList: |
|
|||
893 | # readUnitConfObj.makeXml(projectElement) |
|
|||
894 |
|
890 | |||
895 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
891 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
896 | procUnitConfObj.makeXml(projectElement) |
|
892 | procUnitConfObj.makeXml(projectElement) | |
@@ -907,9 +903,7 class Project(): | |||||
907 |
|
903 | |||
908 | def readXml(self, filename): |
|
904 | def readXml(self, filename): | |
909 |
|
905 | |||
910 | #tree = ET.parse(filename) |
|
|||
911 | self.projectElement = None |
|
906 | self.projectElement = None | |
912 | # self.readUnitConfObjList = [] |
|
|||
913 | self.procUnitConfObjDict = {} |
|
907 | self.procUnitConfObjDict = {} | |
914 |
|
908 | |||
915 | self.projectElement = ElementTree().parse(filename) |
|
909 | self.projectElement = ElementTree().parse(filename) | |
@@ -948,17 +942,11 class Project(): | |||||
948 | self.name, |
|
942 | self.name, | |
949 | self.description) |
|
943 | self.description) | |
950 |
|
944 | |||
951 | # for readUnitConfObj in self.readUnitConfObjList: |
|
|||
952 | # readUnitConfObj.printattr() |
|
|||
953 |
|
||||
954 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
945 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
955 | procUnitConfObj.printattr() |
|
946 | procUnitConfObj.printattr() | |
956 |
|
947 | |||
957 | def createObjects(self): |
|
948 | def createObjects(self): | |
958 |
|
949 | |||
959 | # for readUnitConfObj in self.readUnitConfObjList: |
|
|||
960 | # readUnitConfObj.createObjects() |
|
|||
961 |
|
||||
962 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
950 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
963 | procUnitConfObj.createObjects() |
|
951 | procUnitConfObj.createObjects() | |
964 |
|
952 | |||
@@ -986,8 +974,6 class Project(): | |||||
986 |
|
974 | |||
987 | def run(self): |
|
975 | def run(self): | |
988 |
|
976 | |||
989 | # for readUnitConfObj in self.readUnitConfObjList: |
|
|||
990 | # readUnitConfObj.run() |
|
|||
991 |
|
977 | |||
992 | print "*"*40 |
|
978 | print "*"*40 | |
993 | print " Starting SIGNAL CHAIN PROCESSING " |
|
979 | print " Starting SIGNAL CHAIN PROCESSING " | |
@@ -1027,7 +1013,7 class Project(): | |||||
1027 | print "Process reinitialized" |
|
1013 | print "Process reinitialized" | |
1028 |
|
1014 | |||
1029 | if self.control['stop']: |
|
1015 | if self.control['stop']: | |
1030 | print "Process stopped" |
|
1016 | # print "Process stopped" | |
1031 | break |
|
1017 | break | |
1032 |
|
1018 | |||
1033 | #Closing every process |
|
1019 | #Closing every process | |
@@ -1045,33 +1031,6 class Project(): | |||||
1045 | self.createObjects() |
|
1031 | self.createObjects() | |
1046 | self.connectObjects() |
|
1032 | self.connectObjects() | |
1047 | self.run() |
|
1033 | self.run() | |
1048 |
|
||||
1049 | class ControllerThread(threading.Thread, Project): |
|
|||
1050 |
|
||||
1051 | def __init__(self, filename): |
|
|||
1052 |
|
||||
1053 | threading.Thread.__init__(self) |
|
|||
1054 | Project.__init__(self) |
|
|||
1055 |
|
||||
1056 | self.setDaemon(True) |
|
|||
1057 |
|
||||
1058 | self.filename = filename |
|
|||
1059 | self.control = {'stop':False, 'pause':False} |
|
|||
1060 |
|
||||
1061 | def stop(self): |
|
|||
1062 | self.control['stop'] = True |
|
|||
1063 |
|
||||
1064 | def pause(self): |
|
|||
1065 | self.control['pause'] = not(self.control['pause']) |
|
|||
1066 |
|
||||
1067 | def run(self): |
|
|||
1068 | self.control['stop'] = False |
|
|||
1069 | self.control['pause'] = False |
|
|||
1070 |
|
||||
1071 | self.readXml(self.filename) |
|
|||
1072 | self.createObjects() |
|
|||
1073 | self.connectObjects() |
|
|||
1074 | Project.run(self) |
|
|||
1075 |
|
1034 | |||
1076 | if __name__ == '__main__': |
|
1035 | if __name__ == '__main__': | |
1077 |
|
1036 | |||
@@ -1091,8 +1050,6 if __name__ == '__main__': | |||||
1091 | online=1, |
|
1050 | online=1, | |
1092 | walk=1) |
|
1051 | walk=1) | |
1093 |
|
1052 | |||
1094 | # opObj00 = readUnitConfObj.addOperation(name='printInfo') |
|
|||
1095 |
|
||||
1096 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) |
|
1053 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
1097 |
|
1054 | |||
1098 | opObj10 = procUnitConfObj0.addOperation(name='selectChannels') |
|
1055 | opObj10 = procUnitConfObj0.addOperation(name='selectChannels') | |
@@ -1116,84 +1073,7 if __name__ == '__main__': | |||||
1116 | opObj11.addParameter(name='zmin', value='40', format='int') |
|
1073 | opObj11.addParameter(name='zmin', value='40', format='int') | |
1117 | opObj11.addParameter(name='zmax', value='90', format='int') |
|
1074 | opObj11.addParameter(name='zmax', value='90', format='int') | |
1118 | opObj11.addParameter(name='showprofile', value='1', format='int') |
|
1075 | opObj11.addParameter(name='showprofile', value='1', format='int') | |
1119 |
|
1076 | |||
1120 | # opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='external') |
|
|||
1121 | # opObj11.addParameter(name='idfigure', value='2', format='int') |
|
|||
1122 | # opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') |
|
|||
1123 | # opObj11.addParameter(name='zmin', value='40', format='int') |
|
|||
1124 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
|||
1125 |
|
||||
1126 |
|
||||
1127 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Voltage', inputId=procUnitConfObj0.getId()) |
|
|||
1128 | # |
|
|||
1129 | # opObj12 = procUnitConfObj2.addOperation(name='CohInt', optype='external') |
|
|||
1130 | # opObj12.addParameter(name='n', value='2', format='int') |
|
|||
1131 | # opObj12.addParameter(name='overlapping', value='1', format='int') |
|
|||
1132 | # |
|
|||
1133 | # procUnitConfObj3 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj2.getId()) |
|
|||
1134 | # procUnitConfObj3.addParameter(name='nFFTPoints', value='32', format='int') |
|
|||
1135 | # |
|
|||
1136 | # opObj11 = procUnitConfObj3.addOperation(name='SpectraPlot', optype='external') |
|
|||
1137 | # opObj11.addParameter(name='idfigure', value='2', format='int') |
|
|||
1138 | # opObj11.addParameter(name='wintitle', value='SpectraPlot1', format='str') |
|
|||
1139 | # opObj11.addParameter(name='zmin', value='40', format='int') |
|
|||
1140 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
|||
1141 | # opObj11.addParameter(name='showprofile', value='1', format='int') |
|
|||
1142 |
|
||||
1143 | # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='external') |
|
|||
1144 | # opObj11.addParameter(name='idfigure', value='10', format='int') |
|
|||
1145 | # opObj11.addParameter(name='wintitle', value='RTI', format='str') |
|
|||
1146 | ## opObj11.addParameter(name='xmin', value='21', format='float') |
|
|||
1147 | ## opObj11.addParameter(name='xmax', value='22', format='float') |
|
|||
1148 | # opObj11.addParameter(name='zmin', value='40', format='int') |
|
|||
1149 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
|||
1150 | # opObj11.addParameter(name='showprofile', value='1', format='int') |
|
|||
1151 | # opObj11.addParameter(name='timerange', value=str(60), format='int') |
|
|||
1152 |
|
||||
1153 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
|||
1154 | # opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist') |
|
|||
1155 | # |
|
|||
1156 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='external') |
|
|||
1157 | # opObj12.addParameter(name='n', value='2', format='int') |
|
|||
1158 | # |
|
|||
1159 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') |
|
|||
1160 | # opObj11.addParameter(name='idfigure', value='2', format='int') |
|
|||
1161 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') |
|
|||
1162 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
|||
1163 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
|||
1164 | # |
|
|||
1165 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
|||
1166 | # opObj10.addParameter(name='channelList', value='2,6', format='intlist') |
|
|||
1167 | # |
|
|||
1168 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='external') |
|
|||
1169 | # opObj12.addParameter(name='n', value='2', format='int') |
|
|||
1170 | # |
|
|||
1171 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') |
|
|||
1172 | # opObj11.addParameter(name='idfigure', value='3', format='int') |
|
|||
1173 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') |
|
|||
1174 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
|||
1175 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
|||
1176 |
|
||||
1177 |
|
||||
1178 | # opObj12 = procUnitConfObj1.addOperation(name='decoder') |
|
|||
1179 | # opObj12.addParameter(name='ncode', value='2', format='int') |
|
|||
1180 | # opObj12.addParameter(name='nbauds', value='8', format='int') |
|
|||
1181 | # opObj12.addParameter(name='code0', value='001110011', format='int') |
|
|||
1182 | # opObj12.addParameter(name='code1', value='001110011', format='int') |
|
|||
1183 |
|
||||
1184 |
|
||||
1185 |
|
||||
1186 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId()) |
|
|||
1187 | # |
|
|||
1188 | # opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='external') |
|
|||
1189 | # opObj21.addParameter(name='n', value='2', format='int') |
|
|||
1190 | # |
|
|||
1191 | # opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='external') |
|
|||
1192 | # opObj11.addParameter(name='idfigure', value='4', format='int') |
|
|||
1193 | # opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str') |
|
|||
1194 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
|||
1195 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
|||
1196 |
|
||||
1197 | print "Escribiendo el archivo XML" |
|
1077 | print "Escribiendo el archivo XML" | |
1198 |
|
1078 | |||
1199 | controllerObj.writeXml(filename) |
|
1079 | controllerObj.writeXml(filename) |
General Comments 0
You need to be logged in to leave comments.
Login now