Skip to content

Serial refactor part 3 (BT) #4413

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

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

haslinghuis
Copy link
Member

@haslinghuis haslinghuis commented Apr 6, 2025

  • fix BT reboot and CRC issues (while switching protocols)
    • in between connection operations needed better error and process handling
    • noticed sometimes we need to ask for permission again after re-using BT connection

Copy link

netlify bot commented Apr 6, 2025

Deploy Preview for origin-betaflight-app ready!

Name Link
🔨 Latest commit 5228b45
🔍 Latest deploy log https://app.netlify.com/sites/origin-betaflight-app/deploys/6806ba049a8803000895e738
😎 Deploy Preview https://deploy-preview-4413.app.betaflight.com
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@haslinghuis haslinghuis changed the title Fix BT reboot and CRC issues Fix BT reboot and CRC issues (while switching protocols) Apr 6, 2025
@haslinghuis haslinghuis requested a review from Copilot April 6, 2025 01:49
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/js/utils/AutoDetect.js:114

  • [nitpick] For consistency with other event handlers, consider storing and using a bound reference for 'readSerialAdapter' to ensure reliable removal.
serial.removeEventListener("receive", readSerialAdapter);

src/js/serial.js Outdated
return false;
}

// This will only execute for the already disconnected case or if an error occurred
return result;
Copy link
Preview

Copilot AI Apr 6, 2025

Choose a reason for hiding this comment

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

Returning a synchronous value 'result' in an asynchronous disconnect callback can lead to inconsistent behavior; consider refactoring this method to return a Promise or otherwise handle the asynchronous state more reliably.

Copilot uses AI. Check for mistakes.

@haslinghuis haslinghuis force-pushed the fix-bt-reboot branch 2 times, most recently from 0950ecd to 5225cbb Compare April 6, 2025 02:01
@haslinghuis haslinghuis requested a review from Copilot April 6, 2025 02:03
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

src/js/protocols/WebBluetooth.js:268

  • Ensure tests cover error scenarios in getCharacteristics, such as when the characteristics array is empty or when expected characteristics are missing.
        } catch (error) {

src/js/serial.js:261

  • Consider adding tests to verify that disconnect behaves correctly when the protocol is already disconnected and that the callback is invoked appropriately.
if (!this._protocol.connected) {

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

src/js/serial.js:234

  • [nitpick] The error message 'Failed to disconnect before reconnecting' may benefit from more detailed context (e.g., indicating which protocol is involved) to aid in debugging.
return false;

src/js/protocols/WebBluetooth.js:276

  • [nitpick] While empty notifications are logged with a warning, it may be useful to add handling for a zero-length ArrayBuffer to ensure downstream consumers of the notification event receive consistent data.
if (!event.target.value) {

@haslinghuis haslinghuis force-pushed the fix-bt-reboot branch 3 times, most recently from 3d5a461 to 4d118cb Compare April 6, 2025 02:43
@haslinghuis haslinghuis requested a review from Copilot April 6, 2025 02:44
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

src/js/protocols/WebBluetooth.js:46

  • The event name 'gatserverdisconnected' appears to be misspelled compared to the standard 'gattserverdisconnected'. Please verify and correct the event name to ensure proper handling.
this.bluetooth.addEventListener("gatserverdisconnected", (e) => this.handleRemovedDevice(e.target));

src/js/utils/AutoDetect.js:19

  • The global 'mspHelper' variable may lead to conflicts if multiple AutoDetect instances are created; consider converting it to an instance property.
let mspHelper = null;

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (4)

src/js/protocols/WebBluetooth.js:173

  • [nitpick] Consider renaming 'boundHandleReceiveBytes' to 'handleReceiveBytesBound' to make it clearer that this is a bound method.
this.addEventListener("receive", this.boundHandleReceiveBytes);

src/js/serial.js:233

  • [nitpick] Consider providing additional context in the error message to aid in diagnosing the protocol state during reconnection failures.
console.error(`${this.logHead} Failed to disconnect before reconnecting`);

src/js/utils/AutoDetect.js:120

  • Verify that clearing MSP listeners before calling 'MSP.disconnect_cleanup()' does not interfere with necessary cleanup operations; if order matters, consider reversing the sequence.
MSP.clearListeners();

src/js/protocols/WebBluetooth.js:260

  • [nitpick] Consider standardizing this error message to ensure consistency with other error messages across the codebase.
throw new Error(`Write characteristic not found: ${this.deviceDescription.writeCharacteristic}`);

@haslinghuis haslinghuis changed the title Fix BT reboot and CRC issues (while switching protocols) Serial refactor part 3 Apr 6, 2025
@haslinghuis haslinghuis requested a review from Copilot April 7, 2025 15:36
@haslinghuis haslinghuis force-pushed the fix-bt-reboot branch 2 times, most recently from 5228b45 to 7bed6c5 Compare April 26, 2025 22:20
@haslinghuis haslinghuis marked this pull request as draft April 26, 2025 22:23
@haslinghuis haslinghuis force-pushed the fix-bt-reboot branch 3 times, most recently from a522e54 to 979a0ee Compare May 2, 2025 19:53
Copy link

coderabbitai bot commented May 2, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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 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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

github-actions bot commented May 2, 2025

Preview URL: https://86b7318f.betaflight-configurator.pages.dev

@haslinghuis haslinghuis force-pushed the fix-bt-reboot branch 2 times, most recently from fe05faf to cb5bd86 Compare May 2, 2025 19:57
Copy link
Contributor

github-actions bot commented May 2, 2025

Preview URL: https://98cb9bcc.betaflight-configurator.pages.dev

Copy link
Contributor

github-actions bot commented May 2, 2025

Preview URL: https://665b5770.betaflight-configurator.pages.dev

Copy link
Contributor

github-actions bot commented May 2, 2025

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

Copy link

sonarqubecloud bot commented May 2, 2025

Copy link
Contributor

github-actions bot commented May 2, 2025

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

@haslinghuis haslinghuis changed the title Serial refactor part 3 Serial refactor part 3 (BT) May 2, 2025
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.

2 participants