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