tools/remote/comm_udp: probe Etherbone server on open().
This commit is contained in:
parent
f390161baa
commit
c3660379db
|
@ -26,6 +26,8 @@ class CommUDP(CSRBuilder):
|
|||
return
|
||||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
self.socket.bind(("", self.port))
|
||||
self.socket.settimeout(1)
|
||||
self.probe()
|
||||
|
||||
def close(self):
|
||||
if not hasattr(self, "socket"):
|
||||
|
@ -33,6 +35,23 @@ class CommUDP(CSRBuilder):
|
|||
self.socket.close()
|
||||
del self.socket
|
||||
|
||||
def probe(self):
|
||||
# Send probe request to server...
|
||||
packet = EtherbonePacket()
|
||||
packet.pf = 1
|
||||
packet.encode()
|
||||
self.socket.sendto(packet.bytes, (self.server, self.port))
|
||||
|
||||
# ...and get/check server's response.
|
||||
try:
|
||||
datas, dummy = self.socket.recvfrom(8192)
|
||||
packet = EtherbonePacket(datas)
|
||||
packet.decode()
|
||||
assert packet.pr == 1
|
||||
except:
|
||||
self.close()
|
||||
raise Exception(f"Unable to probe Etherbone server at {self.server}.")
|
||||
|
||||
def read(self, addr, length=None, burst="incr"):
|
||||
assert burst == "incr"
|
||||
length_int = 1 if length is None else length
|
||||
|
|
Loading…
Reference in New Issue