Skip to content

Fix AT32 Configuration can't be saved on MacOS #4455

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 5 commits into
base: master
Choose a base branch
from

Conversation

kedeng
Copy link
Contributor

@kedeng kedeng commented May 1, 2025

Can fix #3514, but not good.

Summary by CodeRabbit

  • New Features
    • Improved compatibility for macOS users when connecting to certain USB devices by automatically adjusting how data is sent.
  • Bug Fixes
    • Enhanced data transmission reliability for specific devices on macOS platforms.

Copy link

coderabbitai bot commented May 1, 2025

Walkthrough

The update introduces platform- and device-specific logic to the WebSerial class for handling data writes. It detects if the user is on macOS and, upon device connection, checks if the connected device is an AT32 flight controller. If both conditions are met, the class enables a new batch writing mode that splits outgoing data into 63-byte chunks and writes them sequentially to the serial port. The send method is modified to conditionally use this batch writing logic, otherwise defaulting to the original write behavior. Two new methods, checkIsNeedBatchWrite and batchWrite, are added to support this functionality. Additionally, a minor fix adjusts the macOS platform string case in the OS detection utility.

Changes

File(s) Change Summary
src/js/protocols/WebSerial.js Added platform/device detection, checkIsNeedBatchWrite(), batchWrite(data), and conditional batch write logic in send().
src/js/utils/checkBrowserCompatibilty.js Corrected macOS platform string from "MacOS" to "macOS" in OS detection logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WebSerial
    participant SerialPort

    User->>WebSerial: connect()
    WebSerial->>WebSerial: checkIsNeedBatchWrite()
    WebSerial->>SerialPort: open()

    User->>WebSerial: send(data, callback)
    alt Batch write needed
        WebSerial->>WebSerial: batchWrite(data)
        loop for each 63-byte chunk
            WebSerial->>SerialPort: write(chunk)
        end
    else
        WebSerial->>SerialPort: write(data)
    end
    WebSerial->>User: callback()
Loading

Assessment against linked issues

Objective Addressed Explanation
Fix inability to save Configuration/Ports tabs on AT32 FCs when using macOS (issue #3514)

Poem

A clever patch, a bunny's delight,
Mac and AT32 now handshake right!
With chunks of sixty-three,
The data hops free—
No more save woes in the moonlit night.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1f1b68f and c0c5ea0.

📒 Files selected for processing (2)
  • src/js/protocols/WebSerial.js (5 hunks)
  • src/js/utils/checkBrowserCompatibilty.js (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/js/utils/checkBrowserCompatibilty.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/js/protocols/WebSerial.js
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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

@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

🧹 Nitpick comments (2)
src/js/protocols/WebSerial.js (2)

58-59: Consider using a more reliable method for platform detection

Using the userAgent string for platform detection is common but can be less reliable as it can be spoofed. For a more robust solution, consider using platform-specific APIs like navigator.platform in combination with userAgent detection.

- this.isMac = /macintosh|mac os x/i.test(navigator.userAgent);
+ this.isMac = /macintosh|mac os x/i.test(navigator.userAgent) && 
+   (navigator.platform.toLowerCase().includes('mac') || navigator.platform.toLowerCase().includes('darwin'));

171-171: Consider adding logging for batch write mode detection

Adding a log statement when batch write mode is enabled would help with debugging and verifying that the condition is correctly triggered for AT32 devices on macOS.

 this.isNeedBatchWrite = this.checkIsNeedBatchWrite();
+if (this.isNeedBatchWrite) {
+    console.log(`${this.logHead} Enabling batch write mode for AT32 on macOS`);
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fd5156e and 3a00a68.

📒 Files selected for processing (1)
  • src/js/protocols/WebSerial.js (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/js/protocols/WebSerial.js (1)
src/js/protocols/devices.js (2)
  • vendorIdNames (68-74)
  • vendorIdNames (68-74)
🔇 Additional comments (2)
src/js/protocols/WebSerial.js (2)

336-338: Good targeted fix for the AT32 on macOS issue

This check correctly implements the condition based on both the platform and the specific device vendor ID.


361-365: The conditional batch writing approach looks good

The implementation maintains backward compatibility for other devices/platforms while introducing the specialized handling for AT32 on macOS.

@haslinghuis
Copy link
Member

@kedeng two more changes please - see #4455 (review)

Copy link
Contributor

github-actions bot commented May 2, 2025

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

@kedeng
Copy link
Contributor Author

kedeng commented May 2, 2025

consider using platform-specific APIs like navigator.platform in combination with userAgent detection.

navigator.platform seems deprecated. https://medium.com/@jortiz.dev/bye-navigator-platform-here-is-the-alternative-939b883bf050

This comment was marked as outdated.

@kedeng
Copy link
Contributor Author

kedeng commented May 2, 2025

Preview URL: https://115e1b0a.betaflight-configurator.pages.dev

Seems preview URL not right, I can see this log on the local machine but not see it in this URL:

 console.log(`${this.logHead} Enabling batch write mode for AT32 on macOS`);

@nerdCopter
Copy link
Member

nerdCopter commented May 2, 2025

@blckmn , multiple preview URL comments are confusing. and the bot adding emojis is ridiculous 😹 . can you change these behaviors? if old comments cannot be removed, maybe they can be hidden as "outdated"
image

This comment was marked as outdated.

Copy link

sonarqubecloud bot commented May 3, 2025

Copy link
Contributor

github-actions bot commented May 3, 2025

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

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.

  • approving for workflow only. i cannot test and would prefer secondary macOS user to test AT32 before merge.

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.

Setup and Configuration tabs will not save when using AT32 FC
3 participants