fix: silly rounding error on UDP stale check

This commit is contained in:
Yui
2026-05-02 22:15:45 -03:00
parent 2515cb748a
commit 3ec50c4004
3 changed files with 3 additions and 6 deletions

2
.gitignore vendored
View File

@@ -1,2 +1,2 @@
*.csv
__pycache__
*/**/__pycache__/

View File

@@ -15,11 +15,10 @@ class UDPClient(SocketClient):
def Send(self, data: str):
now = time.time()
data = "%s/%f" % (data, now)
data = f"{data}/{now}"
self.socket.sendto(data.encode(), (self.ip, self.port))
self.logger.info("UDP_SENT %s" % data)
self._timestamps.add(now)
print(self._timestamps)
self.Receive()
self.staleCheck()
@@ -34,7 +33,6 @@ class UDPClient(SocketClient):
print(timestamp.decode())
self.logger.info("UDP_SUCCESS %s (%s)" % (data.decode(), addr))
self._timestamps.discard(float(timestamp.decode()))
print(self._timestamps)
def staleCheck(self):
if (time.time() - self._last_check) < 1:
@@ -45,7 +43,6 @@ class UDPClient(SocketClient):
if (self._last_check - timestamp) < 10:
continue
self.logger.error("UDP_FAIL %f" % timestamp)
print(self._timestamps)
timedout_timestamps.add(timestamp)
self._last_check = time.time()

View File

@@ -54,7 +54,7 @@ def main():
udp.Connect()
while True:
# tcp.Send("meow")
tcp.Send("meow")
udp.Send("woof")
time.sleep(9)