Skip to content

add rf traffic logging on local rf modules and remote hmlgw-interfaces#5

Open
jp112sdl wants to merge 3 commits into
OpenCCU:mainfrom
jp112sdl:TrafficLogger
Open

add rf traffic logging on local rf modules and remote hmlgw-interfaces#5
jp112sdl wants to merge 3 commits into
OpenCCU:mainfrom
jp112sdl:TrafficLogger

Conversation

@jp112sdl

@jp112sdl jp112sdl commented Jul 13, 2026

Copy link
Copy Markdown
Member
Bildschirmfoto 2026-07-13 um 20 14 14

🌎 WebUI call

  • http://<openccu>/tools/rftrafficlogger.html

🚧 TODO

  • add cleanup in crontab to keep log files only a few days (i.e. 7): 10 0 * * * find /var/log -name "multimacd-traffic-*.log" -mtime +7 -delete
  • add a "Show RF Traffic"-button in WebUI like DevConfig
  • add an option to enable or disable traffic logging in "advanced settings" in the webui
    • 2 new lines in multimacd.conf and rfd.conf are needed
      • Traffic Log = 0/1
      • Traffic Log Directory = /var/log

Summary by CodeRabbit

  • New Features
    • Added optional traffic logging for multimacd and Funk-LAN gateway traffic.
    • Added command-line and configuration controls for enabling logging and selecting the log directory.
    • Logs are organized into daily files with timestamps, direction, protocol details, and signal strength.
    • Added a browser-based traffic viewer with search, filtering, live updates, analysis charts, and CSV export.
    • Added API support for retrieving log dates, traffic data, device details, and version information.
    • Added detection of network-connected gateway interfaces.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2c783de3-f6f0-4eb8-8b0d-46c1180e9722

📥 Commits

Reviewing files that changed from the base of the PR and between cc75a11 and af2ff56.

📒 Files selected for processing (3)
  • src/multimacd/MultimacManager.cpp
  • src/multimacd/Subsystem.cpp
  • src/multimacd/SubsystemManager.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/multimacd/SubsystemManager.cpp
  • src/multimacd/Subsystem.cpp

📝 Walkthrough

Walkthrough

Adds configurable RX/TX traffic logging for multimacd and rfd, daily log rotation, LAN-interface capture, and a CGI/browser interface for querying, decoding, filtering, analyzing, and exporting traffic logs.

Changes

Traffic logging and RF traffic viewer

Layer / File(s) Summary
Logger contracts and startup configuration
src/multimacd/TrafficLogger.h, src/rfd/TrafficLogger.h, src/multimacd/multimacd.cpp, src/multimacd/multimacd.conf, src/rfd/rfd.cpp, src/rfd/BidcosInterface.*, src/rfd/CMakeLists.txt
Defines logger APIs, configures defaults and the -t option, detects LAN interfaces, and wires logger sources into startup and builds.
Daily log file implementation
src/multimacd/TrafficLogger.cpp, src/rfd/TrafficLogger.cpp
Formats protocol-specific traffic, timestamps entries, synchronizes writes, converts payloads to hex, and rotates files by date.
Frame capture integration
src/multimacd/Subsystem.cpp, src/multimacd/SubsystemManager.cpp, src/multimacd/MultimacManager.cpp, src/rfd/BidcosInterfaceConcentrator.cpp
Configures logging and records upstream/downstream multimacd frames plus RX/TX telegrams on LAN interfaces.
CGI traffic API
www/tools/rftrafficlogger-api.cgi
Provides date discovery, offset-based log streaming, cached device metadata, version reporting, configuration lookup, and guarded error responses.
Viewer ingestion and decoding
www/tools/rftrafficlogger.html
Adds the traffic viewer layout, protocol decoding, polling state, log parsing, device naming, and HmIP address resolution.
Filtering, rendering, and analysis
www/tools/rftrafficlogger.html
Adds filters, decoded table rendering, payload highlighting, RSSI/rate charts, and per-device statistics.
Export and polling controls
www/tools/rftrafficlogger.html
Adds sanitized CSV export and coordinates polling, date changes, tabs, controls, initialization, and live rollover.

Estimated code review effort: 5 (Critical) | ~90 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Multimacd
  participant Rfd
  participant TrafficLogger
  participant TrafficLogFiles
  Multimacd->>TrafficLogger: configure and record upstream/downstream frames
  Rfd->>TrafficLogger: configure and record LAN RX/TX telegrams
  TrafficLogger->>TrafficLogFiles: write daily traffic entries
Loading
sequenceDiagram
  participant Browser
  participant TrafficApi
  participant TrafficLogs
  Browser->>TrafficApi: request dates and log chunks
  TrafficApi->>TrafficLogs: scan or read selected logs
  TrafficApi-->>Browser: return dates or text lines
  Browser->>TrafficApi: request device metadata
  TrafficApi-->>Browser: return cached or rebuilt device list
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: RF traffic logging for local modules and remote hmlgw interfaces.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@jp112sdl jp112sdl changed the title add rf traffic logging on local rf modules und remote hmlgw-interfaces add rf traffic logging on local rf modules and remote hmlgw-interfaces Jul 13, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (4)
src/rfd/TrafficLogger.h (1)

46-46: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

_enabled should be std::atomic<bool> for consistency with the multimacd logger.

The multimacd TrafficLogger uses std::atomic<bool> _enabled (line 45 of src/multimacd/TrafficLogger.h) explicitly for lock-free reads on the per-frame fast path. The rfd version uses a plain bool, which is a data race if IsEnabled() is ever called from a different thread than Configure(). While Configure() currently runs in main() before the event loop (rfd.cpp:331-333), making this safe for single-threaded dispatch, the rfd concentrator handles multiple LAN gateway connections and could evolve to use per-connection threads. Aligning with the multimacd pattern prevents a future race.

♻️ Proposed fix
-	bool _enabled;
+	std::atomic<bool> _enabled;

And add #include <atomic> (already present in the multimacd header).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/rfd/TrafficLogger.h` at line 46, Update the rfd TrafficLogger class
member _enabled to std::atomic<bool> and add the required <atomic> header
include, matching the multimacd TrafficLogger pattern while preserving existing
Configure() and IsEnabled() behavior.
src/multimacd/TrafficLogger.h (1)

44-53: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

_directory is read on the fast path without synchronization.

_enabled is correctly atomic, but _directory (line 46) is a plain std::string read in GetLogFile/WriteLine while Configure() writes it. This is safe only if Configure() is called once before any traffic. If Configure() is ever called at runtime (e.g., reload), concurrent reads of _directory would be a data race. Consider documenting this constraint or copying _directory under the mutex in GetLogFile.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/multimacd/TrafficLogger.h` around lines 44 - 53, Protect runtime access
to _directory in GetLogFile and WriteLine by reading or copying it under _mutex,
while Configure() continues updating it under the same lock. Preserve the
fast-path behavior of _enabled and ensure the copied directory remains valid
after the lock is released.
www/tools/rftrafficlogger.html (1)

905-908: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Debounce the high-frequency handlers.

fSearch fires render on every keystroke ("input") and resize fires renderStats on every event. Both run filtered() over up to MAX_KEEP (50000) telegrams and rebuild the table / redraw charts synchronously, which can visibly jank on large logs. A small debounce (~120–200 ms) keeps typing and window resizing smooth without changing behavior.

♻️ Example debounce wrapper
+const debounce = (fn, ms = 150) => { let h; return (...a) => { clearTimeout(h); h = setTimeout(() => fn(...a), ms); }; };
+const renderDebounced = debounce(render);
+const statsDebounced = debounce(renderStats);
 for (const id of ["fSearch", "fDir", "fProto", "fVia", "fType", "fDev", "fHideBcast"]) {
-  $(id).addEventListener(id === "fSearch" ? "input" : "change", render);
+  $(id).addEventListener(id === "fSearch" ? "input" : "change", id === "fSearch" ? renderDebounced : render);
 }
-window.addEventListener("resize", () => { if (state.tab === "stats") renderStats(); });
+window.addEventListener("resize", () => { if (state.tab === "stats") statsDebounced(); });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@www/tools/rftrafficlogger.html` around lines 905 - 908, Debounce the
high-frequency handlers in the filter-listener loop and the window resize
listener: preserve immediate change handling for the non-search filters, but
route fSearch input and resize events through approximately 120–200 ms delayed
callbacks before invoking render or renderStats. Reuse a stable timer per
handler so repeated events cancel the prior pending invocation without changing
the final rendered behavior.
www/tools/rftrafficlogger-api.cgi (1)

230-238: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Avoid caching an empty/failed device list.

If rega_script throws (line 178 catch) or returns no STDOUT, buildDevList still returns a well-formed JSON with an empty devices array. cmdDevList then persists that empty result to CACHEFILE, so device names stay unresolved for up to CACHETTL (600 s) even after ReGa recovers — the user must manually hit "Geräte ↻" to break out. Only cache when the list is actually populated.

♻️ Only persist a non-empty result
     if {$json eq ""} {
         set json [buildDevList]
-        catch {
-            set fh [open $CACHEFILE w]
-            fconfigure $fh -encoding utf-8
-            puts -nonewline $fh $json
-            close $fh
-        }
+        # nur cachen, wenn die Geraeteliste wirklich befuellt ist
+        if {[string match {*"devices":\[{*} $json]} {
+            catch {
+                set fh [open $CACHEFILE w]
+                fconfigure $fh -encoding utf-8
+                puts -nonewline $fh $json
+                close $fh
+            }
+        }
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@www/tools/rftrafficlogger-api.cgi` around lines 230 - 238, Update the caching
block in cmdDevList so CACHEFILE is written only when buildDevList returns a
populated device list, not merely any non-empty JSON string. Inspect the parsed
devices collection or equivalent result and skip the open/write operations when
it is empty, while preserving the existing response behavior and cache handling
for populated lists.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/multimacd/TrafficLogger.h`:
- Around line 44-53: Protect runtime access to _directory in GetLogFile and
WriteLine by reading or copying it under _mutex, while Configure() continues
updating it under the same lock. Preserve the fast-path behavior of _enabled and
ensure the copied directory remains valid after the lock is released.

In `@src/rfd/TrafficLogger.h`:
- Line 46: Update the rfd TrafficLogger class member _enabled to
std::atomic<bool> and add the required <atomic> header include, matching the
multimacd TrafficLogger pattern while preserving existing Configure() and
IsEnabled() behavior.

In `@www/tools/rftrafficlogger-api.cgi`:
- Around line 230-238: Update the caching block in cmdDevList so CACHEFILE is
written only when buildDevList returns a populated device list, not merely any
non-empty JSON string. Inspect the parsed devices collection or equivalent
result and skip the open/write operations when it is empty, while preserving the
existing response behavior and cache handling for populated lists.

In `@www/tools/rftrafficlogger.html`:
- Around line 905-908: Debounce the high-frequency handlers in the
filter-listener loop and the window resize listener: preserve immediate change
handling for the non-search filters, but route fSearch input and resize events
through approximately 120–200 ms delayed callbacks before invoking render or
renderStats. Reuse a stable timer per handler so repeated events cancel the
prior pending invocation without changing the final rendered behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 80674d2b-f1b3-4df7-9d73-d273c5b4f111

📥 Commits

Reviewing files that changed from the base of the PR and between 516f3de and cc75a11.

📒 Files selected for processing (17)
  • src/multimacd/MultimacManager.cpp
  • src/multimacd/Subsystem.cpp
  • src/multimacd/SubsystemManager.cpp
  • src/multimacd/TrafficLogger.cpp
  • src/multimacd/TrafficLogger.h
  • src/multimacd/UpstreamCharConnection.cpp
  • src/multimacd/multimacd.conf
  • src/multimacd/multimacd.cpp
  • src/rfd/BidcosInterface.cpp
  • src/rfd/BidcosInterface.h
  • src/rfd/BidcosInterfaceConcentrator.cpp
  • src/rfd/CMakeLists.txt
  • src/rfd/TrafficLogger.cpp
  • src/rfd/TrafficLogger.h
  • src/rfd/rfd.cpp
  • www/tools/rftrafficlogger-api.cgi
  • www/tools/rftrafficlogger.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants