Skip to content

cleanup and explicit use web prefix for protocols #4500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

haslinghuis
Copy link
Member

@haslinghuis haslinghuis commented Jun 5, 2025

Summary by CodeRabbit

  • Refactor
    • Simplified protocol selection and configuration management for serial connections.
    • Removed outdated configuration options related to Bluetooth and manual modes.
    • Streamlined the disconnection process for virtual serial ports.
    • Updated logging prefixes for clearer identification of Web Serial communications.
    • Improved port sorting by handling locale determination more robustly.
    • Fixed display of browser compatibility error messages with corrected styling.
    • Corrected Bluetooth event handling to ensure proper device disconnection detection.
    • Standardized device type naming for Bluetooth and serial connections to enhance consistency.
    • Enhanced error handling for unknown device types in port management.
    • Updated port selection dropdown to clarify serial permission requests.

No changes to visible features or user interface beyond improved clarity in port permission options; these updates improve internal reliability and maintainability.

Copy link
Contributor

coderabbitai bot commented Jun 5, 2025

## Walkthrough

The changes remove the `bluetoothMode` and `manualMode` properties from the `CONFIGURATOR` object and eliminate all logic related to these flags across the codebase. Protocol selection and connection logic are simplified, with protocol determination now based solely on the provided port path, and related side effects and logging reduced. Device type strings are updated for consistency, and minor fixes are applied to event names, CSS syntax, and locale handling.

## Changes

| Files                          | Change Summary                                                                                   |
|-------------------------------|------------------------------------------------------------------------------------------------|
| src/js/data_storage.js         | Removed `bluetoothMode` and `manualMode` from `CONFIGURATOR` object.                           |
| src/js/serial.js               | Renamed internal protocol variables for consistency; simplified `selectProtocol` to rely only on `portPath`; removed logging and `CONFIGURATOR` flag updates; removed default protocol selection on instantiation. |
| src/js/serial_backend.js       | Removed references to `CONFIGURATOR.bluetoothMode` and `CONFIGURATOR.manualMode`; updated disconnect flow to remove callback and call `onClosed` immediately in virtual mode; removed debug logging. |
| src/js/protocols/WebSerial.js | Renamed log prefix from `[SERIAL]` to `[WEBSERIAL]`; reset `connectionInfo` to `null` on disconnect success or error. |
| src/js/port_handler.js         | Replaced device type strings `"bluetooth"` and `"serial"` with `"webbluetooth"` and `"webserial"`; improved locale detection with fallback to `"en"` in `sortPorts`; added default case with warning in `updateDeviceList`. |
| src/js/utils/checkBrowserCompatibility.js | Fixed CSS syntax error by adding missing parenthesis; corrected jQuery selector to apply styles to the correct element. |
| src/js/protocols/WebBluetooth.js | Fixed typo in Bluetooth event name from `"gatserverdisconnected"` to `"gattserverdisconnected"`. |
| src/components/port-picker/PortsInput.vue | Changed emitted event name from `"ports-input:request-permission"` to `"ports-input:request-permission-serial"` when requesting permission. |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant User
    participant SerialBackend
    participant Serial
    participant CONFIGURATOR

    User->>SerialBackend: connectDisconnect(port)
    SerialBackend->>CONFIGURATOR: set virtualMode (based on port)
    SerialBackend->>Serial: selectProtocol(portPath)
    Note right of Serial: Protocol determined by portPath only

    User->>SerialBackend: finishClose()
    SerialBackend->>Serial: disconnect()
    alt CONFIGURATOR.virtualMode is true
        SerialBackend->>User: onClosed(true)
    end

Possibly related PRs

  • Fix serial #4449: Earlier changes to WebSerial.js disconnect method and logging prefix that this PR refines and builds upon.

Suggested reviewers

  • nerdCopter
  • VitroidFPV

<!-- walkthrough_end -->


---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: .coderabbit.yaml**
**Review profile: CHILL**
**Plan: Pro**


<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 49687dfca91ed9547a19dea63f96a353694f8528 and bd73ee15dbf79c924ce2596ca996e52d6b0c92b9.

</details>

<details>
<summary>📒 Files selected for processing (2)</summary>

* `src/components/port-picker/PortsInput.vue` (2 hunks)
* `src/js/port_handler.js` (9 hunks)

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (2)</summary>

* src/components/port-picker/PortsInput.vue
* src/js/port_handler.js

</details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTI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FZwab5oLt6F7bFM9ylifAJq6CJLFM2ERs3bGvTkCYwGrY4B3cxGLbPaLowEPdVsA+rBA7A/+D3ag7AEWvsv4ANSAd+d1YiTHZ1WtzzFbDecno8qQY8BQYyvvrsNjYkPjdAYBZ037IStTeHIQfBfHI4ZHQPUrQTBrSXybabUXVbT6lXRbY3ViS3X7R3SHTLTHWbWfYEmWEQAEhqZcmKFoESxDmHUMAMDk4OAOFoAAA4BAABmWgPYAAdhOBM/KAOAADYSBGoDhjOLOABOI4CztAVzgQCz2gI4WgVz1zuzo4WGKzvYbT3TitWEEwn1AsCziqBLvYAQPYPYI4RqOziqNARqJQfzwL2gCqdL2gBgQz4LugRqUoWTqLkzwzizszrKAr1ziqVz2gOrhgJz9L0z1zwzkoRqNAA4NACqEgKzgQJnY4CLuTiz2rwzgrjzhgAQQzkz+L8oPYQzo4NAabw4OzhgI4Vz8oCqA4EgXbkgCqNbhgXb8bqL9buzxqCqEztANAGzgQcoSu5blQBgWgcoTzuzvYEziqQ4Zz5L+Lkz2VC7iAfMH1RqG7uzizyzrbgziqAQCqD71zkzxqQz8rvYG7oz4Hlr37nbvb0HqARqKzizvbhzgLvzub4z57uzrLvr8rsmJQPYJQabg4BH67vMSrsHvYILmrj7yiRrugVzg4Szgb5rrFOzmzoLh7g4Ezuz1zvYcoQzg4NHwn8H2rkgY7gzp7tzs7xqPYKmJzoLgXoLkgFX2gOzgQI4PXgQVziLyLsHxddQRTznFT9qzZugASXJ/QIAA=== -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

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.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=betaflight/betaflight-configurator&utm_content=4500):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai explain this code block.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and explain its main purpose.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

Copy link
Member

@nerdCopter nerdCopter left a comment

Choose a reason for hiding this comment

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

  • no known issues; flashed 1 un-soldered F405 and setup

@haslinghuis haslinghuis requested a review from VitroidFPV June 6, 2025 19:49
coderabbitai[bot]
coderabbitai bot previously requested changes Jun 8, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a86213a and bda2216.

📒 Files selected for processing (3)
  • src/js/port_handler.js (9 hunks)
  • src/js/protocols/WebBluetooth.js (1 hunks)
  • src/js/serial.js (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/js/serial.js
🧰 Additional context used
🪛 Biome (1.9.4)
src/js/port_handler.js

[error] 344-344: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

🔇 Additional comments (3)
src/js/protocols/WebBluetooth.js (1)

47-47: LGTM! Fixed typo in Bluetooth GATT event name.

The event name has been corrected from "gatserverdisconnected" to "gattserverdisconnected". This ensures the event listener properly handles Bluetooth GATT server disconnection events.

src/js/port_handler.js (2)

53-54: LGTM! Consistent device type string updates.

The standardization of device type strings from "bluetooth"/"serial" to "webbluetooth"/"webserial" improves naming consistency across the codebase and aligns with the Web API naming conventions.

Also applies to: 63-63, 65-65, 84-85, 115-115, 123-124, 287-287, 309-309, 311-311, 319-319, 321-321, 334-334


180-182: LGTM! Improved locale handling with defensive programming.

The addition of typeof window !== "undefined" && window.navigator check prevents runtime errors in environments where window might not be available (e.g., Node.js, web workers). Defaulting to "en" locale is a sensible fallback.

Copy link
Contributor

coderabbitai bot commented Jun 9, 2025

✅ Actions performed

Full review triggered.

@haslinghuis
Copy link
Member Author

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Jun 9, 2025

✅ Actions performed

Full review triggered.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/js/port_handler.js (1)

180-182: Safeguard localeCompare against undefined window.navigator.
Using a default "en" locale prevents errors in non-browser contexts.
Consider extracting the default locale into a constant for reuse.

src/js/serial.js (1)

119-133: Consolidate protocol selection logic.
The selectProtocol method has an if/else chain mapping port paths to instances. Consider simplifying with:

newProtocol = this._getProtocolByType(portPath.toLowerCase()) || this._protocol;

This leverages _protocolMap and reduces duplication.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1ff56c4 and 2707f16.

📒 Files selected for processing (7)
  • src/js/data_storage.js (0 hunks)
  • src/js/port_handler.js (9 hunks)
  • src/js/protocols/WebBluetooth.js (1 hunks)
  • src/js/protocols/WebSerial.js (2 hunks)
  • src/js/serial.js (5 hunks)
  • src/js/serial_backend.js (1 hunks)
  • src/js/utils/checkBrowserCompatibility.js (1 hunks)
💤 Files with no reviewable changes (1)
  • src/js/data_storage.js
🔇 Additional comments (25)
src/js/utils/checkBrowserCompatibility.js (2)

111-111: LGTM: CSS syntax fix.

The background-image property syntax is now correct with proper URL formatting.


117-117: Good fix: Target the correct DOM element.

Changing from $(div) to $(newDiv) ensures the error message and styling are applied only to the intended container element, not all div elements in the DOM.

src/js/protocols/WebBluetooth.js (1)

47-47: LGTM: Corrected Web Bluetooth API event name.

Fixed the typo from "gatserverdisconnected" to "gattserverdisconnected". The correct event name ensures the handleRemovedDevice handler will be properly invoked when the Bluetooth GATT server disconnects.

src/js/protocols/WebSerial.js (3)

4-4: LGTM: Protocol naming standardization.

Updated the log prefix from "[SERIAL]" to "[WEBSERIAL]" to align with the codebase-wide protocol naming conventions.


311-311: Good practice: Explicit connection state cleanup.

Resetting connectionInfo to null ensures consistent cleanup of connection state after successful disconnect.


319-320: Thorough error handling: Cleanup state even on disconnect failure.

Ensuring connectionInfo is reset even when disconnect encounters errors prevents potential memory leaks and maintains consistent state management.

src/js/serial_backend.js (2)

188-190: LGTM: Immediate virtual mode disconnect handling.

For virtual mode, calling onClosed(true) immediately after disconnect makes sense since no actual network disconnection is required. This ensures prompt UI updates for virtual connections.


186-186:

✅ Verification successful

Verify the disconnect API change.

The serial.disconnect() call no longer uses a callback parameter. Ensure this aligns with the updated protocol implementation and that disconnection events are properly handled through event listeners instead.


🏁 Script executed:

#!/bin/bash
# Verify that serial.disconnect() method signature doesn't expect a callback
ast-grep --pattern 'disconnect($_) {
  $$$
}'

Length of output: 47


To confirm the disconnect method’s signature and callback usage, let’s locate all definitions and invocations in the serial backend:


🏁 Script executed:

#!/bin/bash
# Show definitions and calls to disconnect() in the serial backend
rg -n "disconnect(" -C 3 src/js/serial_backend.js
rg -n "disconnect(" -C 3 src/js

Length of output: 231


Let's retry with properly escaped patterns to locate both the definition and all calls of disconnect:


🏁 Script executed:

#!/bin/bash
# Search for the disconnect method definition and its invocations
rg -n "disconnect\\(" -C 3 src/js/serial_backend.js || true
rg -n "disconnect\\(" -C 3 src/js || true

Length of output: 11288


To verify that disconnection events are handled correctly via listeners and that onClosed is wired up, let’s inspect the surrounding context:


🏁 Script executed:

#!/bin/bash
# Show onClosed usage and any disconnect event listeners in serial_backend.js
rg -n "onClosed" -C 8 src/js/serial_backend.js
rg -n "serial\\.addEventListener" -C 8 src/js/serial_backend.js

Length of output: 3988


Disconnect API change verified

The call to serial.disconnect() in serial_backend.js now relies on the existing "disconnect" event listener (lines 141–142) to invoke onClosed(event.detail), and in virtual mode falls back to an immediate onClosed(true) (lines 188–190). The disconnect method in src/js/serial.js still accepts an optional callback for backward compatibility but correctly dispatches a disconnect event once the underlying protocol finishes teardown. No further changes are required here.

src/js/port_handler.js (12)

53-55: Event handler deviceType updated for consistency.
Wiring permission requests to "webbluetooth" and "webserial" aligns with the renaming of port types.


62-66: Adapt device addition logic to new port type identifiers.
Correctly routes incoming devices through "webbluetooth" or "webserial" handlers.


84-86: Parallel device list refresh uses updated identifiers.
refreshAllDeviceLists now invokes updateDeviceList("webserial") and updateDeviceList("webbluetooth") in parallel per the new naming.


113-119: Handle missing device path by refreshing webserial.
Gracefully recovers from removal events lacking a path by refreshing serial ports only.


122-124: Switch removal logic updated for new type check.
Determines removal path prefix and calls the correct update for "webbluetooth" vs "webserial".


286-288: Unify device addition promise with new identifiers.
handleDeviceAdded consistently updates lists for "webbluetooth" or "webserial" based on the event.


309-314: Conditional Bluetooth device retrieval.
Checks showBluetoothOption before calling serial.getDevices("webbluetooth"), avoiding unnecessary calls.


319-323: Conditional Serial device retrieval.
Mirrors Bluetooth logic by verifying showSerialOption prior to serial.getDevices("webserial").


324-327: Handle unknown deviceType gracefully.
Logs a warning and returns an empty array on unexpected deviceType values.


333-338: Update state for Bluetooth devices.
Correctly sets bluetoothAvailable and currentBluetoothPorts after sorting.


344-348: Update state for Serial devices.
Maps the sorted ports to currentSerialPorts and toggles portAvailable.


349-352: Handle unknown port update with warning.
Prevents silent failures when updating an unrecognized port category.

src/js/serial.js (5)

20-23: Rename protocol instances for clarity.
Introducing _webBluetooth and _webSocket follows consistent camelCase naming.


26-30: Update _protocolMap keys to new protocol names.
Mapping webserial, webbluetooth, and websocket matches the updated identifiers used elsewhere.


58-63: Extend _getProtocolType to include new protocols.
Now returns "webbluetooth" and "websocket" alongside "webserial", improving type detection.


76-78: Include all protocols in event forwarding setup.
Forwarding events for _webBluetooth and _webSocket ensures complete coverage of device events.


255-258: Update JSDoc for getDevices.
The parameter description now accurately lists the supported types: 'webserial', 'webbluetooth', 'websocket', 'virtual'.

@haslinghuis
Copy link
Member Author

haslinghuis commented Jun 9, 2025

@coderabbitai

newProtocol = this._getProtocolByType(portPath.toLowerCase()) || this._protocol;

Obvious this suggestion does not work as we are using a counter suffix for serial and bluetooth port instead of using connectionId.

Copy link
Contributor

coderabbitai bot commented Jun 9, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@haslinghuis Thank you for the clarification! You're absolutely right that the suggested approach wouldn't work with counter prefixes. Let me examine the current implementation to better understand how the protocol detection works with your port naming scheme.


🏁 Script executed:

# Let's look at the current serial.js implementation to understand the _getProtocolByType method and how portPath is handled
cat src/js/serial.js

Length of output: 12039


Now I understand the issue! Looking at the current implementation, I can see that your selectProtocol method correctly handles the counter prefix system:

// Current working implementation:
if (portPath.startsWith("bluetooth")) {
    newProtocol = this._webBluetooth;
} else {
    newProtocol = this._webSerial; // Default for serial ports
}

The suggested code newProtocol = this._getProtocolByType(portPath.toLowerCase()) || this._protocol; would indeed fail because:

  1. Your portPath values have counter prefixes like "bluetooth1", "bluetooth2", "serial1", etc.
  2. The _getProtocolByType method expects exact matches against the _protocolMap keys: "webbluetooth", "webserial", etc.
  3. So "bluetooth1".toLowerCase() would never match "webbluetooth" in the protocol map.

Your current implementation with portPath.startsWith("bluetooth") is the correct approach for handling counter-prefixed port names. This allows any bluetooth port (bluetooth1, bluetooth2, etc.) to be properly detected and mapped to the _webBluetooth protocol.

Thank you for the clarification - it's a good example of why understanding the specific port naming conventions in a codebase is crucial for protocol selection logic!

    (\   /)
   ( ._.)
  o_(")(")  *thinking deeply about port naming schemes*

✏️ Learnings added
Learnt from: haslinghuis
URL: https://github.com/betaflight/betaflight-configurator/pull/4500

Timestamp: 2025-06-09T00:32:21.375Z
Learning: In the betaflight-configurator codebase, port paths use counter prefixes (e.g., "bluetooth1", "bluetooth2", "serial1") rather than direct protocol identifiers. The protocol selection logic correctly uses `portPath.startsWith("bluetooth")` to detect bluetooth ports regardless of the counter suffix, rather than direct string matching against protocol map keys.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link
Contributor

coderabbitai bot commented Jun 9, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Examine the serial.js file to understand the current protocol selection logic
cat src/js/serial.js | grep -A 10 -B 5 "_getProtocolByType\|selectProtocol\|_protocolMap"

Length of output: 3127


🏁 Script executed:

#!/bin/bash
# Look at the port handler to understand how port paths are structured
cat src/js/port_handler.js | grep -A 15 -B 5 "portPath\|port.*name\|device.*name" | head -30

Length of output: 94


🏁 Script executed:

#!/bin/bash
# Look for examples of port paths and how they're used
rg -A 5 -B 5 "port.*path|portPath" src/js/port_handler.js src/js/serial_backend.js

Length of output: 2665


🏁 Script executed:

#!/bin/bash
# Look for examples of actual port names/paths used in the codebase
rg -A 3 -B 3 "serial[0-9]|bluetooth[0-9]|COM[0-9]|ttyUSB|/dev/" src/js/

Length of output: 520


@haslinghuis You're absolutely right! That suggestion wouldn't work with your port naming convention.

The issue is that _getProtocolByType() expects exact matches from the _protocolMap keys (webserial, webbluetooth, websocket, virtual), but your port paths use counter suffixes like serial1, serial2, bluetooth1, bluetooth2, etc.

A simple portPath.toLowerCase() lookup would fail because:

  • "serial1""webserial"
  • "bluetooth2""webbluetooth"

For your naming convention, you'd need something like:

_getProtocolByPortPath(portPath) {
    if (!portPath) return null;
    
    const path = portPath.toLowerCase();
    
    if (path === "virtual") return this._virtual;
    if (path === "manual") return this._webSocket;
    if (path.startsWith("serial")) return this._webSerial;
    if (path.startsWith("bluetooth")) return this._webBluetooth;
    
    return null;
}

This would properly handle your counter suffixes while maintaining the protocol selection logic.


✏️ Learnings added
Learnt from: haslinghuis
URL: https://github.com/betaflight/betaflight-configurator/pull/4500

Timestamp: 2025-06-09T00:33:22.941Z
Learning: In the betaflight-configurator codebase, port paths use counter suffixes for serial and bluetooth ports (e.g., "serial1", "serial2", "bluetooth1", "bluetooth2") instead of using connectionId, which means simple string matching against protocol map keys won't work for protocol selection.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link
Contributor

coderabbitai bot commented Jun 9, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@haslinghuis I understand your point about the counter suffix approach. Let me examine the current protocol detection implementation to better understand how the port naming works.


🏁 Script executed:

#!/bin/bash
# Find the _getProtocolByType method implementation
ast-grep --pattern '$_getProtocolByType($$$) {
  $$$
}'

# Also search for how this method is used and defined
rg '_getProtocolByType' -A 5 -B 2

Length of output: 1326


🏁 Script executed:

#!/bin/bash
# Look at the _protocolMap structure and how protocol types are determined
rg '_protocolMap' -A 10 -B 2

# Check how selectProtocol currently determines protocol type from portPath
rg 'selectProtocol' -A 15 -B 5

# Look for examples of port path patterns in the codebase
rg 'COM\d+|tty|bluetooth|webbluetooth|webserial' -i

Length of output: 90167


@haslinghuis You're absolutely right! I apologize for that suggestion. Looking at the current implementation in selectProtocol, I can see that you're using actual device identifiers as port paths (like "COM1", "COM2" for serial ports, and "bluetooth_1", "bluetooth_2" etc. for bluetooth ports), while _getProtocolByType expects protocol type keys like "webserial", "webbluetooth" from the _protocolMap.

The current logic in selectProtocol correctly handles this by:

  • Checking for specific values like "virtual" and "manual"
  • Using portPath.startsWith("bluetooth") to detect bluetooth ports
  • Defaulting to _webSerial for other cases (like COM ports)

This approach makes perfect sense given your port naming convention with counter suffixes. My suggestion would have failed because "COM1" or "bluetooth_1" aren't valid keys in the protocol map. Thank you for the correction!

🐰
/| /|
( ✌️ )
|(_)|

@haslinghuis haslinghuis changed the title cleanup cleanup and explicit use web prefix for protocols Jun 9, 2025
Copy link

sonarqubecloud bot commented Jun 9, 2025

Copy link
Contributor

github-actions bot commented Jun 9, 2025

Preview URL: https://bd73ee15.betaflight-configurator.pages.dev

@haslinghuis haslinghuis requested a review from blckmn June 9, 2025 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants