Skip to content

SC App#2523

Draft
gerth2 wants to merge 6 commits into
PhotonVision:mainfrom
gerth2:hey_bro_wanna_hear_my_idea_for_an_app
Draft

SC App#2523
gerth2 wants to merge 6 commits into
PhotonVision:mainfrom
gerth2:hey_bro_wanna_hear_my_idea_for_an_app

Conversation

@gerth2

@gerth2 gerth2 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Description

Making a first pass at a SystemCore App for PhotonVision

Meta

Merge checklist:

  • Pull Request title is short, imperative summary of proposed changes
  • The description documents the what and why, including events that led to this PR
  • If this PR changes behavior or adds a feature, user documentation is updated
  • If this PR touches photon-serde, all messages have been regenerated and hashes have not changed unexpectedly
  • If this PR touches configuration, this is backwards compatible with all settings going back to the previous seasons's last release (seasons end after champs ends)
  • If this PR touches pipeline settings or anything related to data exchange, the frontend typing is updated
  • If this PR addresses a bug, a regression test for it is added
  • If this PR adds a dependency, the license has been checked for compatibility and steps taken to follow it

gerth2 added 6 commits June 25, 2026 16:56
…d documentation

- Add complete type hints throughout Python backend (photon_sc_app.py)
  * All function signatures include parameter and return type annotations
  * Use Optional[], Dict[], list[] generic types for clarity
  * Union types for service instantiation polymorphism
- Format code with black for consistency and PEP 8 compliance
- Enhance docstrings across all classes and methods
  * Module-level overview explaining architecture and deployment modes
  * SocketActivatedService: systemd socket activation protocol documentation
  * LocalService: development server details
  * ServiceHandler: HTTP routing and status/tabs endpoint details
  * Comprehensive signal_handler documentation
- Update frontend JavaScript with detailed JSDoc comments
  * Explain tab switching logic and event handling
  * Document URL parsing and error handling in fetchTabs()
  * Clear function-level comments with parameters and return types
- Restore iframe sandbox attribute for security
- Remove broken cross-origin proxy endpoint
- Add CI/CD integration: build-ipk job to GitHub Actions
  * Automatically build .ipk artifacts on push
  * Upload to release assets
- Add run_local.sh and run_local.bat for convenient local development
- Update .gitignore for build artifacts (photon-sc-app/build/, *.ipk)

All Python code now passes syntax validation and black formatting checks.
… refresh intervals

Discovery Suite Architecture:
- Modular discovery strategies: mDNS, network scan (10.TE.AM.0/24), port 5800 check, NetworkTables
- Background DiscoveryCache thread for low-CPU periodic updates
- Independent refresh intervals for fast (mDNS, port checks) vs slow (network scan) strategies

Background Discovery Features:
- DiscoveryCache class manages periodic discovery in daemon thread
- Fast strategies default to 10-second cycles (mDNS, port verification)
- Slow strategies default to 60-second cycles (network scan, NetworkTables)
- Tunable via command-line args: --discovery-fast-interval, --discovery-slow-interval
- Can disable fast/slow strategies with --discovery-disable-fast/--discovery-disable-slow
- Thread-safe cache using RLock, responsive to stop signal with 0.5s sleep precision
- Low CPU overhead: sleeps most of the time, wakes only for periodic discovery

ServiceHandler Integration:
- /tabs endpoint now serves results from DiscoveryCache instead of blocking on discovery
- Instant response even if discovery is running (cache coherency via lock)
- Multiple requests don't trigger redundant discovery

Both SocketActivatedService and LocalService now:
- Create and pass DiscoveryCache to request handlers
- Start discovery thread on service startup
- Cleanly stop discovery thread on shutdown

Additional improvements:
- Enhanced styles.css with .empty-state styling for no-dashboards case
- Updated logger to use string formatting instead of print()
- Added team number to discovery log output
- Updated docstrings to explain background caching architecture
- Rewrite networktables_discovery.py to connect to the roboRIO NT
  server, enumerate subtables under /photonvision/, validate cameras
  by checking for rawBytes (same logic as PhotonCamera.java), and
  resolve coprocessor hostnames via mDNS
- Update aggregator.py to pass team_number to NT strategy
- Remove unused imports (threading, discover_all, EventFlags)
- Add NT structure reference to README
- Add NT4 persist files to gitignore
logger = logging.getLogger(__name__)


def discover_mdns() -> Set[str]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We could consider instead using #351 and the robotpy bindings of wpilib's multicast resolver to discover photonvision instances

Comment on lines +60 to +62
instance = NetworkTableInstance.create()
instance.setServerTeam(team_number, NT_SERVER_PORT)
instance.startClient(NT_CLIENT_IDENTITY)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe youll need a MultiSubscriber here, like how PhotonCamera works.

        // Existing is enough to make this multisubscriber do its thing
        topicNameSubscriber =
                new MultiSubscriber(instance, new String[] {"/photonvision/"}, PubSubOption.TOPICS_ONLY);

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