@@ -0,0 +1,165 | |||||
|
1 | import socket | |||
|
2 | ||||
|
3 | class TCPComm: | |||
|
4 | ||||
|
5 | __HEADER = "JRO" | |||
|
6 | __TYPE = "ABS" | |||
|
7 | ||||
|
8 | def __init__(self, ipSource, ipDestino, portDestino, asServer=False): | |||
|
9 | ||||
|
10 | self.ipSource = ipSource | |||
|
11 | self.ipDestino = ipDestino | |||
|
12 | self.portDestino = portDestino | |||
|
13 | self.addr = (ipDestino,portDestino) | |||
|
14 | ||||
|
15 | self.sc = "none" | |||
|
16 | self.answer = "none" #test | |||
|
17 | self.asServer = False | |||
|
18 | self.len = 0 | |||
|
19 | self.crc = 0 | |||
|
20 | ||||
|
21 | self.openSocket(asServer) | |||
|
22 | ||||
|
23 | def openSocket(self, asServer): | |||
|
24 | ||||
|
25 | #self.socket_c = socket.socket(AF_INET,SOCK_DGRAM) | |||
|
26 | # self.socket_c = socket.socket() | |||
|
27 | # self.socket_c.connect((self.ipDestino, self.portDestino)) | |||
|
28 | ||||
|
29 | if asServer: | |||
|
30 | self.socket_c = socket.socket() | |||
|
31 | # self.configAsServer() | |||
|
32 | self.socket_c.bind(self.addr) | |||
|
33 | self.asServer = True | |||
|
34 | else: | |||
|
35 | # self.configAsClient() | |||
|
36 | self.asServer = False #Socket is opened at the sendData function | |||
|
37 | ||||
|
38 | # def configAsClient(self): | |||
|
39 | #Buscar broadcast TCP | |||
|
40 | # self.socket_c.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | |||
|
41 | # self.socket_c.connect(self.addr) | |||
|
42 | # pass | |||
|
43 | ||||
|
44 | # def configAsServer(self): | |||
|
45 | # | |||
|
46 | # self.socket_c.bind(self.addr) | |||
|
47 | ||||
|
48 | def waitData(self, nbytes = 1024): | |||
|
49 | ||||
|
50 | print "\nWaiting some client." | |||
|
51 | ||||
|
52 | if self.asServer == False: | |||
|
53 | # Short data through ethernet | |||
|
54 | trama_rx = self.socket_c.recv(nbytes) | |||
|
55 | else: | |||
|
56 | self.socket_c.listen(1) | |||
|
57 | sc, addr = self.socket_c.accept() | |||
|
58 | self.sc = sc | |||
|
59 | self.answer = addr | |||
|
60 | # Big data through ethernet | |||
|
61 | trama_rx = "" | |||
|
62 | while True: | |||
|
63 | tmp = self.sc.recv(nbytes) | |||
|
64 | trama_rx = trama_rx + tmp | |||
|
65 | if trama_rx[-4:] == "quit": | |||
|
66 | break | |||
|
67 | ||||
|
68 | print "\nThis socket has received some data." | |||
|
69 | ||||
|
70 | ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) | |||
|
71 | ||||
|
72 | return ipSource, ipDestino, cmd, data | |||
|
73 | ||||
|
74 | def waitServer(self, nbytes = 1024): | |||
|
75 | ||||
|
76 | print "\nWaiting some client." | |||
|
77 | self.socket_c.listen(1) | |||
|
78 | sc, addr = self.socket_c.accept() | |||
|
79 | self.sc = sc | |||
|
80 | self.answer = addr | |||
|
81 | # Big data through ethernet | |||
|
82 | trama_rx = "" | |||
|
83 | while True: | |||
|
84 | tmp = self.sc.recv(nbytes) | |||
|
85 | trama_rx = trama_rx + tmp | |||
|
86 | if trama_rx[-4:] == "quit": | |||
|
87 | break | |||
|
88 | ||||
|
89 | print "\nThis socket has received some data from: " + str(self.answer) | |||
|
90 | ||||
|
91 | ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) | |||
|
92 | ||||
|
93 | return ipSource, ipDestino, cmd, data | |||
|
94 | ||||
|
95 | def waitClient(self, nbytes = 1024): | |||
|
96 | ||||
|
97 | print "\nWaiting the server." | |||
|
98 | # Short data through ethernet | |||
|
99 | trama_rx = self.socket_c.recv(nbytes) | |||
|
100 | ||||
|
101 | print "\nThis socket has received this data: " + str(trama_rx) | |||
|
102 | ||||
|
103 | ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) | |||
|
104 | ||||
|
105 | return ipSource, ipDestino, cmd, data | |||
|
106 | ||||
|
107 | def sendData(self, cmd, data, id): | |||
|
108 | ||||
|
109 | trama_tx = self.__HEADER + ":" + self.__TYPE + ":" + str(self.ipSource) + ":" + str(self.ipDestino) + \ | |||
|
110 | ":" + str(self.len) + ":" + str(cmd) + ":" + str(data) + ":" + str(self.crc) | |||
|
111 | ||||
|
112 | if self.portDestino == 7000: | |||
|
113 | trama_tx = trama_tx + ":" + "quit" | |||
|
114 | # Send messages | |||
|
115 | if self.asServer == False: | |||
|
116 | host = "192.168.1." + str(id) | |||
|
117 | self.socket_c.connect((host, self.portDestino)) | |||
|
118 | self.socket_c.send(trama_tx) | |||
|
119 | else: | |||
|
120 | self.sc.send(trama_tx) | |||
|
121 | print "Sending message:[" + trama_tx + "]" | |||
|
122 | ||||
|
123 | def sendData2(self, cmd, data, ipDestino): | |||
|
124 | ||||
|
125 | trama_tx = self.__HEADER + ":" + self.__TYPE + ":" + str(self.ipSource) + ":" + str(ipDestino) + \ | |||
|
126 | ":" + str(self.len) + ":" + str(cmd) + ":" + str(data) + ":" + str(self.crc) + ":" + "quit" | |||
|
127 | ||||
|
128 | if self.asServer == True: | |||
|
129 | self.SendAsServer(trama_tx) | |||
|
130 | else: | |||
|
131 | self.SendAsClient(ipDestino, trama_tx) | |||
|
132 | ||||
|
133 | def SendAsServer(self, trama_tx): | |||
|
134 | ||||
|
135 | self.sc.send(trama_tx) | |||
|
136 | print "Sending message:[" + trama_tx + "] to: " + str(self.answer) | |||
|
137 | ||||
|
138 | ||||
|
139 | def SendAsClient(self, ipDestino, trama_tx): | |||
|
140 | ||||
|
141 | self.socket_c.connect((ipDestino, self.portDestino)) | |||
|
142 | self.socket_c.send(trama_tx) | |||
|
143 | print "Sending message:[" + trama_tx + "] to: " + ipDestino | |||
|
144 | ||||
|
145 | def __getTrama(self, trama): | |||
|
146 | ||||
|
147 | FrameList = trama.split(':') | |||
|
148 | ||||
|
149 | header = FrameList[0] | |||
|
150 | TypeOfInstrument = FrameList[1] | |||
|
151 | ipSource = FrameList[2] | |||
|
152 | ipDestino = FrameList[3] | |||
|
153 | len = FrameList[4] | |||
|
154 | cmd = FrameList[5] | |||
|
155 | data = FrameList[6] | |||
|
156 | crc = FrameList[7] | |||
|
157 | trash = FrameList[8] | |||
|
158 | ||||
|
159 | return ipSource, ipDestino, cmd, data | |||
|
160 | ||||
|
161 | def close_socket(self): | |||
|
162 | self.socket_c.close() | |||
|
163 | ||||
|
164 | def open_socket(self): | |||
|
165 | self.socket_c = socket.socket() No newline at end of file |
@@ -4,11 +4,11 | |||||
4 | import time |
|
4 | import time | |
5 | import numpy as np |
|
5 | import numpy as np | |
6 |
|
6 | |||
7 | import library |
|
7 | import library2 | |
8 |
|
8 | |||
9 | class ABSClient: |
|
9 | class ABSClient: | |
10 |
|
10 | |||
11 |
def __init__(self,ipSource="localhost", ipDestino="192.168.1.1 |
|
11 | def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000): | |
12 |
|
12 | |||
13 | self.ipSource = ipSource |
|
13 | self.ipSource = ipSource | |
14 | self.ipDestino = ipDestino |
|
14 | self.ipDestino = ipDestino | |
@@ -18,7 +18,7 | |||||
18 |
|
18 | |||
19 | def createObjects(self): |
|
19 | def createObjects(self): | |
20 |
|
20 | |||
21 | self.commObj = library.TCPComm(self.ipSource, self.ipDestino, self.portDestino) |
|
21 | self.commObj = library2.TCPComm(self.ipSource, self.ipDestino, self.portDestino) | |
22 |
|
22 | |||
23 | def sendFile(self, filename): |
|
23 | def sendFile(self, filename): | |
24 |
|
24 | |||
@@ -30,15 +30,21 | |||||
30 | F_Obj.close() |
|
30 | F_Obj.close() | |
31 | FileStr = "".join(FileList) |
|
31 | FileStr = "".join(FileList) | |
32 | data = FileStr |
|
32 | data = FileStr | |
33 |
|
33 | |||
34 | self.commObj.sendData(cmd="SNDF", data=data) |
|
34 | self.commObj.open_socket() | |
35 | self.commObj.waitData() |
|
35 | # self.commObj.sendData(cmd="SNDF", data=data, id = 117) | |
|
36 | self.commObj.sendData2(cmd="SNDF", data=data, ipDestino = self.ipDestino) | |||
|
37 | # self.commObj.waitData() | |||
|
38 | self.commObj.waitClient() | |||
36 | self.commObj.close_socket() |
|
39 | self.commObj.close_socket() | |
37 |
|
40 | |||
38 | def changeBeam(self, newBeam): |
|
41 | def changeBeam(self, newBeam): | |
39 |
|
42 | |||
40 | self.commObj.sendData(cmd="CHGB", data=newBeam) |
|
43 | self.commObj.open_socket() | |
41 | self.commObj.waitData() |
|
44 | # self.commObj.sendData(cmd="CHGB", data=newBeam, id = 117) | |
|
45 | self.commObj.sendData2(cmd="CHGB", data=newBeam, ipDestino = self.ipDestino) | |||
|
46 | # self.commObj.waitData() | |||
|
47 | self.commObj.waitClient() | |||
42 | self.commObj.close_socket() |
|
48 | self.commObj.close_socket() | |
43 |
|
49 | |||
44 | def __writeFile(self, filename, data): |
|
50 | def __writeFile(self, filename, data): | |
@@ -48,9 +54,12 | |||||
48 | fobj.close() |
|
54 | fobj.close() | |
49 |
|
55 | |||
50 | def getStatus(self, data): |
|
56 | def getStatus(self, data): | |
51 |
|
57 | |||
52 | self.commObj.sendData(cmd="ANST", data = data) |
|
58 | self.commObj.open_socket() | |
53 | ipSource, ipDestino, cmd, data = self.commObj.waitData() |
|
59 | # self.commObj.sendData(cmd="ANST", data = data, id = 117) | |
|
60 | self.commObj.sendData2(cmd="ANST", data = data, ipDestino = self.ipDestino) | |||
|
61 | # ipSource, ipDestino, cmd, data = self.commObj.waitData() | |||
|
62 | ipSource, ipDestino, cmd, data = self.commObj.waitClient() | |||
54 | self.commObj.close_socket() |
|
63 | self.commObj.close_socket() | |
55 | self.__writeFile("report.txt", data) |
|
64 | self.__writeFile("report.txt", data) | |
56 |
|
65 | |||
@@ -479,9 +488,9 | |||||
479 | filename = "experimento1.abs" |
|
488 | filename = "experimento1.abs" | |
480 |
|
489 | |||
481 | absObj = ABSClient() |
|
490 | absObj = ABSClient() | |
482 | absObj.sendFile(filename) |
|
491 | # absObj.sendFile(filename) | |
483 | # absObj.changeBeam("0") |
|
492 | # absObj.changeBeam("0") | |
484 |
|
|
493 | absObj.changeBeam("1") | |
485 | # absObj.changeBeam("2") |
|
494 | # absObj.changeBeam("2") | |
486 | # absObj.changeBeam("3") |
|
495 | # absObj.changeBeam("3") | |
487 | # absObj.changeBeam("4") |
|
496 | # absObj.changeBeam("4") |
@@ -13,6 +13,7 | |||||
13 | self.addr = (ipDestino,portDestino) |
|
13 | self.addr = (ipDestino,portDestino) | |
14 | self.answer = "none" #test |
|
14 | self.answer = "none" #test | |
15 | self.mode = "none" |
|
15 | self.mode = "none" | |
|
16 | ||||
16 |
|
17 | |||
17 | self.openSocket(asServer) |
|
18 | self.openSocket(asServer) | |
18 |
|
19 | |||
@@ -78,7 +79,8 | |||||
78 |
|
79 | |||
79 | class TCPComm: |
|
80 | class TCPComm: | |
80 |
|
81 | |||
81 |
__HEADER = " |
|
82 | __HEADER = "JRO" | |
|
83 | __TYPE = "ABS" | |||
82 |
|
84 | |||
83 | def __init__(self, ipSource, ipDestino, portDestino, asServer=False): |
|
85 | def __init__(self, ipSource, ipDestino, portDestino, asServer=False): | |
84 |
|
86 | |||
@@ -90,30 +92,35 | |||||
90 | self.sc = "none" |
|
92 | self.sc = "none" | |
91 | self.answer = "none" #test |
|
93 | self.answer = "none" #test | |
92 | self.mode = "none" |
|
94 | self.mode = "none" | |
|
95 | self.len = 0 | |||
|
96 | self.crc = 0 | |||
93 |
|
97 | |||
94 | self.openSocket(asServer) |
|
98 | self.openSocket(asServer) | |
95 |
|
99 | |||
96 | def openSocket(self, asServer): |
|
100 | def openSocket(self, asServer): | |
97 |
|
101 | |||
98 | #self.socket_c = socket.socket(AF_INET,SOCK_DGRAM) |
|
102 | #self.socket_c = socket.socket(AF_INET,SOCK_DGRAM) | |
99 | self.socket_c = socket.socket() |
|
103 | # self.socket_c = socket.socket() | |
100 | # self.socket_c.connect((self.ipDestino, self.portDestino)) |
|
104 | # self.socket_c.connect((self.ipDestino, self.portDestino)) | |
101 |
|
105 | |||
102 | if asServer: |
|
106 | if asServer: | |
103 |
self. |
|
107 | self.socket_c = socket.socket() | |
|
108 | # self.configAsServer() | |||
|
109 | self.socket_c.bind(self.addr) | |||
104 | self.mode = "server" |
|
110 | self.mode = "server" | |
105 | else: |
|
111 | else: | |
106 | self.configAsClient() |
|
112 | # self.configAsClient() | |
107 | self.mode = "client" |
|
113 | self.mode = "client" #Socket is opened at the sendData function | |
108 |
|
114 | |||
109 | def configAsClient(self): |
|
115 | # def configAsClient(self): | |
110 | #Buscar broadcast TCP |
|
116 | #Buscar broadcast TCP | |
111 | # self.socket_c.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) |
|
117 | # self.socket_c.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | |
112 | self.socket_c.connect(self.addr) |
|
118 | # self.socket_c.connect(self.addr) | |
113 |
|
119 | # pass | ||
114 | def configAsServer(self): |
|
120 | ||
115 |
|
121 | # def configAsServer(self): | ||
116 | self.socket_c.bind(self.addr) |
|
122 | # | |
|
123 | # self.socket_c.bind(self.addr) | |||
117 |
|
124 | |||
118 | def waitData(self, nbytes = 1024): |
|
125 | def waitData(self, nbytes = 1024): | |
119 |
|
126 | |||
@@ -135,21 +142,22 | |||||
135 | if trama_rx[-4:] == "quit": |
|
142 | if trama_rx[-4:] == "quit": | |
136 | break |
|
143 | break | |
137 |
|
144 | |||
138 |
print "\nThis socket has received some data |
|
145 | print "\nThis socket has received some data." | |
139 | print self.answer |
|
|||
140 |
|
146 | |||
141 | ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) |
|
147 | ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) | |
142 |
|
148 | |||
143 | return ipSource, ipDestino, cmd, data |
|
149 | return ipSource, ipDestino, cmd, data | |
144 |
|
150 | |||
145 | def sendData(self, cmd, data): |
|
151 | def sendData(self, cmd, data, id): | |
146 |
|
152 | |||
|
153 | trama_tx = self.__HEADER + ":" + self.__TYPE + ":" + str(self.ipSource) + ":" + str(self.ipDestino) + ":" + str(self.len) + ":" + str(cmd) + ":" + str(data) + ":" + str(self.crc) | |||
|
154 | ||||
147 | if self.portDestino == 7000: |
|
155 | if self.portDestino == 7000: | |
148 | trama_tx = self.__HEADER + ":" + str(self.ipSource) + ":" + str(self.ipDestino) + ":" + str(cmd) + ":" + str(data) + ":" + "quit" |
|
156 | trama_tx = trama_tx + ":" + "quit" | |
149 | else: |
|
|||
150 | trama_tx = data |
|
|||
151 | # Send messages |
|
157 | # Send messages | |
152 | if self.mode == "client": |
|
158 | if self.mode == "client": | |
|
159 | host = "192.168.1." + str(id) | |||
|
160 | self.socket_c.connect((host, self.portDestino)) | |||
153 | self.socket_c.send(trama_tx) |
|
161 | self.socket_c.send(trama_tx) | |
154 | else: |
|
162 | else: | |
155 | self.sc.send(trama_tx) |
|
163 | self.sc.send(trama_tx) | |
@@ -160,16 +168,22 | |||||
160 | FrameList = trama.split(':') |
|
168 | FrameList = trama.split(':') | |
161 |
|
169 | |||
162 | header = FrameList[0] |
|
170 | header = FrameList[0] | |
163 |
|
|
171 | TypeOfInstrument = FrameList[1] | |
164 |
ip |
|
172 | ipSource = FrameList[2] | |
165 |
|
|
173 | ipDestino = FrameList[3] | |
166 |
|
|
174 | len = FrameList[4] | |
167 |
|
|
175 | cmd = FrameList[5] | |
|
176 | data = FrameList[6] | |||
|
177 | crc = FrameList[7] | |||
|
178 | trash = FrameList[8] | |||
168 |
|
179 | |||
169 | return ipSource, ipDestino, cmd, data |
|
180 | return ipSource, ipDestino, cmd, data | |
170 |
|
181 | |||
171 | def close_socket(self): |
|
182 | def close_socket(self): | |
172 | self.socket_c.close() |
|
183 | self.socket_c.close() | |
|
184 | ||||
|
185 | def open_socket(self): | |||
|
186 | self.socket_c = socket.socket() | |||
173 |
|
187 | |||
174 | #class FTPComm: |
|
188 | #class FTPComm: | |
175 | # |
|
189 | # |
@@ -1,10 +1,10 | |||||
1 | import os |
|
1 | import os | |
2 | import library |
|
2 | import library2 | |
3 | import time |
|
3 | import time | |
4 |
|
4 | |||
5 | class ABSServer: |
|
5 | class ABSServer: | |
6 |
|
6 | |||
7 |
def __init__(self,ipSource="localhost", ipDestino="192.168.1.1 |
|
7 | def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000, ipDestino2="192.168.1.11", portDestino2=5500): | |
8 |
|
8 | |||
9 | self.ipSource = ipSource |
|
9 | self.ipSource = ipSource | |
10 | self.ipDestino = ipDestino |
|
10 | self.ipDestino = ipDestino | |
@@ -13,37 +13,34 | |||||
13 | self.ipDestino2 = ipDestino2 |
|
13 | self.ipDestino2 = ipDestino2 | |
14 | self.portDestino2 = portDestino2 |
|
14 | self.portDestino2 = portDestino2 | |
15 |
|
15 | |||
16 | self.ftpPortDestino = ftpPortDestino |
|
|||
17 | self.experiment_name = "default" |
|
|||
18 | self.tx_buffer = "default" |
|
16 | self.tx_buffer = "default" | |
|
17 | self.rx_buffer = "default" | |||
19 |
|
18 | |||
20 | self.createObjects() |
|
19 | self.createObjects() | |
21 |
|
20 | |||
22 | def createObjects(self): |
|
21 | def createObjects(self): | |
23 |
|
22 | |||
24 | asServer = True |
|
23 | asServer = True | |
25 |
self.commServerObj = library.TCPComm( |
|
24 | self.commServerObj = library2.TCPComm("Central_Control", self.ipDestino, self.portDestino, asServer) | |
26 |
self.commClientObj = library. |
|
25 | self.commClientObj = library2.TCPComm("Central_Control", self.ipDestino2, self.portDestino2) | |
27 | #self.ftpCommObj = library.FTPComm(self.ipSource, self.ipDestino, self.ftpPortDestino) |
|
|||
28 |
|
||||
29 |
|
26 | |||
30 | def waitRequest(self): |
|
27 | def waitRequest(self): | |
31 |
|
28 | |||
32 | ipSource, ipDestino, cmd, self.datarx = self.commServerObj.waitData() |
|
29 | # Using rx buffer | |
33 |
|
30 | ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitServer() | ||
34 | datarpta = "OK" |
|
|||
35 |
|
31 | |||
36 | if cmd == "SNDF": |
|
32 | if cmd == "SNDF": | |
37 | self.sendFile2Modules() |
|
33 | datarpta = self.sendFile2Modules(mode=2, cmd = cmd) | |
38 |
|
34 | |||
39 | if cmd == "CHGB": |
|
35 | if cmd == "CHGB": | |
40 | self.changeBeam() |
|
36 | datarpta = self.changeBeam(cmd = cmd) | |
41 |
|
37 | |||
42 | if cmd == "ANST": |
|
38 | if cmd == "ANST": | |
43 |
self.getStatus(mode= |
|
39 | self.getStatus(mode=4, cmd = cmd) | |
|
40 | # Using tx buffer | |||
44 | datarpta = self.tx_buffer |
|
41 | datarpta = self.tx_buffer | |
45 |
|
42 | |||
46 | self.commServerObj.sendData(cmd=cmd, data=datarpta) |
|
43 | self.commServerObj.sendData2(cmd=cmd, data=datarpta, ipDestino = ipSource) | |
47 |
|
44 | |||
48 | def checkModule(self, address): |
|
45 | def checkModule(self, address): | |
49 |
|
46 | |||
@@ -62,7 +59,6 | |||||
62 |
|
59 | |||
63 | for address in range(1,65): |
|
60 | for address in range(1,65): | |
64 | if address in enaModules: |
|
61 | if address in enaModules: | |
65 | # status_array.append("192.168.1." + str(base + i + 1) + " [1 1]\n") |
|
|||
66 | status_array.append("192.168.1." + str(address) + " [1 1]\n") |
|
62 | status_array.append("192.168.1." + str(address) + " [1 1]\n") | |
67 | else: |
|
63 | else: | |
68 | status_array.append("192.168.1." + str(address) + " [0 0]\n") |
|
64 | status_array.append("192.168.1." + str(address) + " [0 0]\n") | |
@@ -92,10 +88,17 | |||||
92 | self.__writeReport(enaModules) |
|
88 | self.__writeReport(enaModules) | |
93 | return enaModules |
|
89 | return enaModules | |
94 |
|
90 | |||
95 | def sendFile2Modules(self): |
|
91 | def sendFile2Modules(self, mode, cmd): | |
|
92 | ||||
|
93 | if mode == 1: | |||
|
94 | self.__sendFile2Modules1() | |||
|
95 | else: | |||
|
96 | self.__sendFile2Modules2(cmd) | |||
|
97 | ||||
|
98 | def __sendFile2Modules1(self): | |||
96 |
|
99 | |||
97 | #Needed for the loop |
|
100 | #Needed for the loop | |
98 |
rx_frame_list = self. |
|
101 | rx_frame_list = self.rx_buffer.split('\n',2) | |
99 |
|
102 | |||
100 | self.experiment_name = rx_frame_list[0] |
|
103 | self.experiment_name = rx_frame_list[0] | |
101 | experiment_number = rx_frame_list[1] |
|
104 | experiment_number = rx_frame_list[1] | |
@@ -103,7 +106,8 | |||||
103 |
|
106 | |||
104 | lst_control_modules = str_control_modules.split("------\n") |
|
107 | lst_control_modules = str_control_modules.split("------\n") | |
105 |
|
108 | |||
106 | enaModules = self.checkAntenna() |
|
109 | # enaModules = self.checkAntenna() | |
|
110 | enaModules = [11,12,13,14] | |||
107 |
|
111 | |||
108 | for address in range(1,65): |
|
112 | for address in range(1,65): | |
109 |
|
113 | |||
@@ -117,6 +121,44 | |||||
117 | os.system(cmd) |
|
121 | os.system(cmd) | |
118 |
|
122 | |||
119 | self.__loadFile() |
|
123 | self.__loadFile() | |
|
124 | ||||
|
125 | def __sendFile2Modules2(self,cmd): | |||
|
126 | ||||
|
127 | #Needed for the loop | |||
|
128 | rx_frame_list = self.rx_buffer.split('\n',2) | |||
|
129 | correct = 0 | |||
|
130 | failure = 0 | |||
|
131 | header = rx_frame_list[0] + "\n" | |||
|
132 | str_control_modules = rx_frame_list[2] | |||
|
133 | ||||
|
134 | lst_control_modules = str_control_modules.split("------\n") | |||
|
135 | ||||
|
136 | # enaModules = self.checkAntenna() | |||
|
137 | enaModules = [11,12,13,14] | |||
|
138 | ||||
|
139 | for id in range(1,65): | |||
|
140 | ||||
|
141 | if id not in enaModules: | |||
|
142 | continue | |||
|
143 | #tcp client needed | |||
|
144 | self.commClientObj.open_socket() | |||
|
145 | ip = "192.168.1." + str(id) | |||
|
146 | self.commClientObj.sendData2(cmd, header + lst_control_modules[id-1], ip) | |||
|
147 | ipSource, ipDestino, cmd, tmp = self.commClientObj.waitClient() | |||
|
148 | self.commClientObj.close_socket() | |||
|
149 | ||||
|
150 | if tmp == "OK": | |||
|
151 | correct = correct + 1 | |||
|
152 | else: | |||
|
153 | failure = failure + 1 | |||
|
154 | ||||
|
155 | if correct == len(enaModules): | |||
|
156 | rpta = "OK" | |||
|
157 | else: | |||
|
158 | rpta = "Failure" | |||
|
159 | ||||
|
160 | return rpta | |||
|
161 | ||||
120 |
|
162 | |||
121 | def __writeModuleFile(self, filename, str): |
|
163 | def __writeModuleFile(self, filename, str): | |
122 |
|
164 | |||
@@ -142,25 +184,52 | |||||
142 | self.commClientObj.sendData("none", "CARGA:" + self.experiment_name + ":") |
|
184 | self.commClientObj.sendData("none", "CARGA:" + self.experiment_name + ":") | |
143 | self.commClientObj.sendData("none", "CAMBIA:0:") |
|
185 | self.commClientObj.sendData("none", "CAMBIA:0:") | |
144 |
|
186 | |||
145 | def changeBeam(self): |
|
187 | def changeBeam(self, cmd): | |
146 |
|
188 | |||
147 | #rpta = self.commClientObj.sendTxRxCommand(cmd='CAMBIA', data="0") |
|
189 | correct = 0 | |
148 | self.commClientObj.sendData("none", "CAMBIA:" + self.datarx + ":") |
|
190 | failure = 0 | |
149 |
|
191 | # enaModules = self.checkAntenna() | ||
150 | def getStatus(self,mode): |
|
192 | enaModules = [11,12,13,14] | |
|
193 | ||||
|
194 | for id in range(1,65): | |||
|
195 | if id not in enaModules: | |||
|
196 | continue | |||
|
197 | ||||
|
198 | self.commClientObj.open_socket() | |||
|
199 | ip = "192.168.1." + str(id) | |||
|
200 | self.commClientObj.sendData2(cmd, self.rx_buffer, ip) | |||
|
201 | # ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData() | |||
|
202 | ipSource, ipDestino, cmd, tmp = self.commClientObj.waitClient() | |||
|
203 | self.commClientObj.close_socket() | |||
|
204 | ||||
|
205 | if tmp == "OK": | |||
|
206 | correct = correct + 1 | |||
|
207 | else: | |||
|
208 | failure = failure + 1 | |||
|
209 | ||||
|
210 | if correct == len(enaModules): | |||
|
211 | rpta = "OK" | |||
|
212 | else: | |||
|
213 | rpta = "Failure" | |||
|
214 | ||||
|
215 | return rpta | |||
|
216 | ||||
|
217 | def getStatus(self, mode, cmd): | |||
151 |
|
218 | |||
152 | if mode == 1: |
|
219 | if mode == 1: | |
153 | self.__getStsMode1() |
|
220 | self.__getStsMode1() | |
154 | elif mode == 2: |
|
221 | elif mode == 2: | |
155 | self.__getStsMode2() |
|
222 | self.__getStsMode2() | |
|
223 | elif mode == 3: | |||
|
224 | self.__getStsMode3() | |||
156 | else: |
|
225 | else: | |
157 |
self.__getStsMode |
|
226 | self.__getStsMode4(cmd) | |
158 |
|
227 | |||
159 |
|
228 | |||
160 | def __getStsMode1(self): |
|
229 | def __getStsMode1(self): | |
161 | #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0") |
|
230 | #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0") | |
162 |
self.commClientObj.sendData("CHEQUEO:" + self. |
|
231 | self.commClientObj.sendData("CHEQUEO:" + self.rx_buffer + ":") | |
163 |
seconds = int (self. |
|
232 | seconds = int (self.rx_buffer) | |
164 | # Give 5 seconds to the control modules |
|
233 | # Give 5 seconds to the control modules | |
165 | time.sleep(seconds) |
|
234 | time.sleep(seconds) | |
166 | # Checking the module connection |
|
235 | # Checking the module connection | |
@@ -199,8 +268,8 | |||||
199 | def __getStsMode2(self): |
|
268 | def __getStsMode2(self): | |
200 |
|
269 | |||
201 | #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0") |
|
270 | #rpta = self.commClientObj.sendTxRxCommand(cmd='CHEQUEO', data="0") | |
202 |
self.commClientObj.sendData("CHEQUEO:" + self. |
|
271 | self.commClientObj.sendData("CHEQUEO:" + self.rx_buffer + ":") | |
203 |
seconds = int (self. |
|
272 | seconds = int (self.rx_buffer) | |
204 | # Give 5 seconds to the control modules |
|
273 | # Give 5 seconds to the control modules | |
205 | time.sleep(seconds) |
|
274 | time.sleep(seconds) | |
206 | # Checking the module connection |
|
275 | # Checking the module connection | |
@@ -264,13 +333,33 | |||||
264 |
|
333 | |||
265 | def __getStsMode3(self): |
|
334 | def __getStsMode3(self): | |
266 |
|
335 | |||
267 |
self.commClientObj.sendData("none", "CHEQUEO:" + self. |
|
336 | self.commClientObj.sendData("none", "CHEQUEO:" + self.rx_buffer + ":") | |
268 |
seconds = int (self. |
|
337 | seconds = int (self.rx_buffer) | |
269 | # Give 5 seconds to the control modules |
|
338 | # Give 5 seconds to the control modules | |
270 | time.sleep(seconds) |
|
339 | time.sleep(seconds) | |
271 |
|
340 | |||
272 | self.__getModuleFile(filename = "Verificacion") |
|
341 | self.__getModuleFile(filename = "Verificacion") | |
273 |
|
342 | |||
|
343 | def __getStsMode4(self, cmd): | |||
|
344 | ||||
|
345 | content_str = "" | |||
|
346 | # enaModules = self.checkAntenna() | |||
|
347 | enaModules = [11,12,13,14] | |||
|
348 | ||||
|
349 | for id in range(1,65): | |||
|
350 | if id not in enaModules: | |||
|
351 | continue | |||
|
352 | ||||
|
353 | self.commClientObj.open_socket() | |||
|
354 | ip = "192.168.1." + str(id) | |||
|
355 | self.commClientObj.sendData2(cmd, self.rx_buffer, ip) | |||
|
356 | ipSource, ipDestino, cmd, tmp = self.commClientObj.waitClient() | |||
|
357 | self.commClientObj.close_socket() | |||
|
358 | ||||
|
359 | content_str = content_str + tmp | |||
|
360 | # self.__AddingHeader(content_list, title = "Verification_file") | |||
|
361 | #Using tx buffer | |||
|
362 | self.tx_buffer = content_str | |||
274 |
|
363 | |||
275 | if __name__ == '__main__': |
|
364 | if __name__ == '__main__': | |
276 |
|
365 |
General Comments 0
You need to be logged in to leave comments.
Login now