truma_inetbox: implement master mode auto-discovery and device scanning

udp_lin_receiver: add option to suppress repeated identical messages
This commit is contained in:
2025-09-14 21:07:18 +02:00
parent aa5a85ec42
commit 98ad6caab9
3 changed files with 41 additions and 4 deletions

View File

@@ -77,6 +77,7 @@ def run():
ap.add_argument("--duration", type=float, default=0.0, help="Stop after N seconds (0 = no limit)")
ap.add_argument("--quiet", action="store_true", help="No console output, only CSV")
ap.add_argument("--pid-diff", action="store_true", help="Track textual 'PID ..' lines and only print when data changes")
ap.add_argument("--suppress-repeats", action="store_true", help="Suppress repeated identical messages (shows first + count)")
ap.add_argument("--buffer", type=int, default=4096, help="Receive buffer size (default: 4096)")
args = ap.parse_args()
@@ -101,6 +102,9 @@ def run():
start = time.time()
last_by_pid: Dict[int, Tuple[int, ...]] = {}
last_message = None
repeat_count = 0
last_display_time = 0
while True:
if args.duration and (time.time() - start) >= args.duration:
@@ -129,6 +133,33 @@ def run():
# Console output
if not args.quiet:
# Format the display message
if is_text and as_text:
display_msg = f"{ts} {src_ip}:{src_port} ({size}B) TEXT: {as_text}"
else:
display_msg = f"{ts} {src_ip}:{src_port} ({size}B) HEX: {hexstr}"
# Handle repeat suppression
if args.suppress_repeats:
current_msg_key = as_text if is_text else hexstr
current_time = time.time()
if current_msg_key == last_message:
repeat_count += 1
# Show periodic updates for long repeated sequences
if current_time - last_display_time > 5.0: # Every 5 seconds
print(f"... repeated {repeat_count} times (last: {ts})")
last_display_time = current_time
else:
# Message changed
if repeat_count > 0:
print(f"... repeated {repeat_count} times total")
print(display_msg)
last_message = current_msg_key
repeat_count = 0
last_display_time = current_time
continue
if args.pid_diff and is_text:
parsed = maybe_parse_pid_and_data(as_text)
if parsed:
@@ -140,10 +171,7 @@ def run():
continue
# default console print
if is_text and as_text:
print(f"{ts} {src_ip}:{src_port} ({size}B) TEXT: {as_text}")
else:
print(f"{ts} {src_ip}:{src_port} ({size}B) HEX: {hexstr}")
print(display_msg)
if __name__ == "__main__":