##// END OF EJS Templates
Changes on waitData function: library, server and client
imanay -
r84:85
parent child
Show More
@@ -31,20 +31,16
31 31 FileStr = "".join(FileList)
32 32 data = FileStr
33 33
34 self.commObj.open_socket()
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()
34 self.commObj.open_socket()
35 self.commObj.sendData(cmd="SNDF", data=data, ipDestino = self.ipDestino)
36 self.commObj.waitData()
39 37 self.commObj.close_socket()
40 38
41 39 def changeBeam(self, newBeam):
42 40
43 41 self.commObj.open_socket()
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.sendData(cmd="CHGB", data=newBeam, ipDestino = self.ipDestino)
43 self.commObj.waitData()
48 44 self.commObj.close_socket()
49 45
50 46 def __writeFile(self, filename, data):
@@ -55,19 +51,17
55 51
56 52 def getControlModuleStatus(self, data):
57 53
58 self.commObj.open_socket()
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.open_socket()
55 self.commObj.sendData(cmd="ANST", data = data, ipDestino = self.ipDestino)
56 ipSource, ipDestino, cmd, data = self.commObj.waitData()
63 57 self.commObj.close_socket()
64 58 self.__writeFile("report.txt", data)
65 59
66 60 def getConnectionStatus(self):
67 61
68 62 self.commObj.open_socket()
69 self.commObj.sendData2(cmd="NTST", data = "none", ipDestino = "192.168.1.117")
70 ipSource, ipDestino, cmd, data = self.commObj.waitClient()
63 self.commObj.sendData(cmd="NTST", data = "none", ipDestino = "192.168.1.117")
64 ipSource, ipDestino, cmd, data = self.commObj.waitData()
71 65 self.commObj.close_socket()
72 66 self.__writeFile("connection_status.txt", data)
73 67
@@ -45,34 +45,17
45 45 #
46 46 # self.socket_c.bind(self.addr)
47 47
48 def waitData(self, nbytes = 1024):
48 def waitData(self):
49 if self.asServer == True:
50 trama_rx = self.waitAsServer()
51 else:
52 trama_rx = self.waitAsClient()
49 53
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 54 ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx)
71 55
72 56 return ipSource, ipDestino, cmd, data
73
74 def waitServer(self, nbytes = 1024):
75
57
58 def waitAsServer(self, nbytes = 1024):
76 59 print "\nWaiting some client."
77 60 self.socket_c.listen(1)
78 61 sc, addr = self.socket_c.accept()
@@ -87,40 +70,18
87 70 break
88 71
89 72 print "\nThis socket has received some data from: " + str(self.answer)
90
91 ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx)
92 73
93 return ipSource, ipDestino, cmd, data
94
95 def waitClient(self, nbytes = 1024):
74 return trama_rx
96 75
76 def waitAsClient(self, nbytes = 1024):
97 77 print "\nWaiting the server."
98 78 # Short data through ethernet
99 79 trama_rx = self.socket_c.recv(nbytes)
100
101 80 print "\nThis socket has received this data: " + str(trama_rx)
102 81
103 ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx)
82 return trama_rx
104 83
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):
84 def sendData(self, cmd, data, ipDestino):
124 85
125 86 trama_tx = self.__HEADER + ":" + self.__TYPE + ":" + str(self.ipSource) + ":" + str(ipDestino) + \
126 87 ":" + str(self.len) + ":" + str(cmd) + ":" + str(data) + ":" + str(self.crc) + ":" + "quit"
@@ -28,7 +28,7
28 28 def waitRequest(self):
29 29
30 30 #Using rx buffer
31 ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitServer()
31 ipSource, ipDestino, cmd, self.rx_buffer = self.commServerObj.waitData()
32 32
33 33 if cmd == "SNDF":
34 34 datarpta = self.__sendFile2Modules(cmd = cmd)
@@ -46,7 +46,7
46 46 #Using tx buffer
47 47 datarpta = self.enaModules
48 48
49 self.commServerObj.sendData2(cmd=cmd, data=datarpta, ipDestino = ipSource)
49 self.commServerObj.sendData(cmd=cmd, data=datarpta, ipDestino = ipSource)
50 50
51 51 def checkModule(self, address):
52 52
@@ -115,8 +115,8
115 115 #tcp client needed
116 116 self.commClientObj.open_socket()
117 117 ip = "192.168.1." + str(id)
118 self.commClientObj.sendData2(cmd, header + lst_control_modules[id-1], ip)
119 ipSource, ipDestino, cmd, tmp = self.commClientObj.waitClient()
118 self.commClientObj.sendData(cmd, header + lst_control_modules[id-1], ip)
119 ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData()
120 120 self.commClientObj.close_socket()
121 121
122 122 if tmp == "OK":
@@ -144,8 +144,8
144 144
145 145 self.commClientObj.open_socket()
146 146 ip = "192.168.1." + str(id)
147 self.commClientObj.sendData2(cmd, self.rx_buffer, ip)
148 ipSource, ipDestino, cmd, tmp = self.commClientObj.waitClient()
147 self.commClientObj.sendData(cmd, self.rx_buffer, ip)
148 ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData()
149 149 self.commClientObj.close_socket()
150 150
151 151 if tmp == "OK":
@@ -172,8 +172,8
172 172
173 173 self.commClientObj.open_socket()
174 174 ip = "192.168.1." + str(id)
175 self.commClientObj.sendData2(cmd, self.rx_buffer, ip)
176 ipSource, ipDestino, cmd, tmp = self.commClientObj.waitClient()
175 self.commClientObj.sendData(cmd, self.rx_buffer, ip)
176 ipSource, ipDestino, cmd, tmp = self.commClientObj.waitData()
177 177 self.commClientObj.close_socket()
178 178
179 179 content_str = content_str + tmp
General Comments 0
You need to be logged in to leave comments. Login now