Skip to content

Commit 928becd

Browse files
committed
Improve the dis_reciever example
Loop indefinitely until we get no data in 3 seconds
1 parent 10f241e commit 928becd

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

examples/dis_receiver.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,24 @@
1717
udpSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
1818
udpSocket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
1919
udpSocket.bind(("", UDP_PORT))
20+
udpSocket.settimeout(3) # exit if we get nothing in this many seconds
21+
2022
print("Created UDP socket {}".format(UDP_PORT))
2123

2224
gps = GPS();
2325

2426
def recv():
25-
data, addr = udpSocket.recvfrom(1024) # buffer size in bytes
26-
print("Received {} bytes".format(len(data)))
27+
data = udpSocket.recv(1024) # buffer size in bytes
2728

2829
aPdu = createPdu(data);
30+
31+
print("Received Pdu type {}, {} bytes".format(aPdu.pduType, len(data)), flush=True)
32+
2933
if aPdu.pduType == 1: #PduTypeDecoders.EntityStatePdu:
3034
loc = (aPdu.entityLocation.x, aPdu.entityLocation.y, aPdu.entityLocation.z)
3135
lla = gps.ecef2lla(loc)
3236
print("Pdu location is {} {} {}".format(lla[0], lla[1], lla[2]))
3337

3438

35-
recv()
39+
while True:
40+
recv()

0 commit comments

Comments
 (0)