-
Notifications
You must be signed in to change notification settings - Fork 2
feat(qe): Improve SerialPortTool #2044
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
Conversation
Thank you for following naming conventions! 😻 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Reviewer's Guide by SourceryThis pull request introduces the jSerialComm library as a new dependency. It updates the dependency information in No diagrams generated as the changes look simple and do not need a visual representation. File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Their most recently public accepted PR is: #2041 |
""" Walkthrough本次更改在项目的依赖管理部分新增了对 Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
⏰ Context from checks skipped due to timeout of 90000ms (9)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @unknowIfGuestInDream - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider grouping related dependency updates together in a single commit for better organization.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Qodana Community for JVMIt seems all right 👌 No new problems were found according to the checks applied 💡 Qodana analysis was run in the pull request mode: only the changed files were checked Contact Qodana teamContact us at qodana-support@jetbrains.com
|
There was a problem hiding this 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 (1)
.idea/artifacts/javafxTool_qe_mac_jar.xml (1)
20-20
: 新增 jSerialComm 依赖元素。
在该行中添加了 jSerialComm 库的依赖,其路径和版本号(2.11.0)看似正确。请确认此依赖确实满足项目串口通信功能的扩展需求,并建议在相关文档中补充说明这一新增依赖的信息。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
.idea/artifacts/javafxTool_qe_mac_jar.xml
(3 hunks).idea/artifacts/javafxTool_qe_win_jar.xml
(3 hunks)qe/src/main/java/com/tlcsdm/qe/tools/SerialPortTool.java
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- qe/src/main/java/com/tlcsdm/qe/tools/SerialPortTool.java
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: build (21, windows-latest, false)
- GitHub Check: build (17, ubuntu-latest, false)
- GitHub Check: build (21, macos-latest, false)
- GitHub Check: build (17, macos-latest, false)
- GitHub Check: build (21, ubuntu-latest, false)
- GitHub Check: build (17, windows-latest, false)
- GitHub Check: qodana
- GitHub Check: Summary
🔇 Additional comments (5)
.idea/artifacts/javafxTool_qe_win_jar.xml (3)
6-8
: 模块输出元素顺序调整
修改后,module-output
元素的顺序由原先的默认排序调整为依次为javafxTool-core
、javafxTool-frame
和javafxTool-qe
。这种重新排序看起来符合依赖管理的预期,但请确认该顺序不会影响构建结果和运行时资源加载。
20-20
: 新增 jSerialComm 依赖的提取目录
在第20行中添加了用于jSerialComm-2.11.0.jar
的<element id="extracted-dir">
,这已正确反映了新增依赖库的需求。请验证该文件路径与版本号与项目中其他部分保持一致,同时确保相关文档也得到了相应更新。
79-79
: 文件结尾格式检查
在末尾(第79行)更新了</component>
标签。请确保整体 XML 结构正确且符合 IDE 的配置规范,避免因格式问题导致构建失败。.idea/artifacts/javafxTool_qe_mac_jar.xml (2)
6-8
: 确认模块输出元素顺序是否符合预期。
这部分代码通过新增<element id="module-output" ... />
元素调整了模块的输出顺序(分别为javafxTool-core
、javafxTool-frame
与javafxTool-qe
),请确认这种顺序调整不会影响构建产物的依赖关系和打包流程。
70-70
: 修正 javafx-swing 库路径。
第 70 行中更正了 extracted-dir 的路径,现为$MAVEN_REPOSITORY$/org/openjfx/javafx-swing/21.0.4/javafx-swing-21.0.4.jar
。请确认该路径与项目要求一致,确保在构建过程中能够正确引用该库。
There was a problem hiding this 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
🔭 Outside diff range comments (1)
qe/src/main/java/com/tlcsdm/qe/tools/SerialPortTool.java (1)
580-586
: 🛠️ Refactor suggestion数据接收处理需要改进
当前的数据接收处理仅将数据打印到控制台,而没有更新UI。应将接收到的数据显示到界面上,并根据用户设置的选项决定是否以十六进制格式显示。
@Override public void serialEvent(SerialPortEvent event) { byte[] newData = event.getReceivedData(); - System.out.println("Received data of size: " + newData.length); - for (int i = 0; i < newData.length; ++i) - System.out.print((char) newData[i]); - System.out.println("\n"); + // 更新接收计数 + Platform.runLater(() -> { + int count = Integer.parseInt(recvCount.getText()) + newData.length; + recvCount.setText(String.valueOf(count)); + + // 根据用户设置决定以文本还是十六进制格式显示 + if (recvShowHex.isSelected()) { + recvTextAear.appendText(bytesToHexString(newData) + " "); + } else { + recvTextAear.appendText(new String(newData)); + } + + // 如果需要显示接收时间 + if (recvShowTime.isSelected()) { + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS"); + recvTextAear.appendText(" [" + sdf.format(new Date()) + "]\n"); + } + }); }
🧹 Nitpick comments (4)
qe/src/main/java/com/tlcsdm/qe/tools/SerialPortTool.java (4)
331-341
: 建议优化串口参数设置逻辑串口参数设置使用了难以阅读的三元嵌套表达式来处理校验位转换。这种写法虽然功能正确,但降低了代码可读性。
- serialPort.setComPortParameters(Integer.parseInt(serPortSpeed.getValue()), - Integer.parseInt(serPortDataBit.getValue()), Integer.parseInt(serPortStopBit.getValue()), - serPortCheckBit.getValue().equals("NONE") ? 0 : serPortCheckBit.getValue().equals("ODD") ? 1 : - serPortCheckBit.getValue().equals("EVEN") ? 2 : serPortCheckBit.getValue().equals( - "SPACE") ? 3 : 0); + // 将校验位字符串转换为对应的整数值 + int parity; + switch(serPortCheckBit.getValue()) { + case "ODD": + parity = 1; // SerialPort.ODD_PARITY + break; + case "EVEN": + parity = 2; // SerialPort.EVEN_PARITY + break; + case "SPACE": + parity = 3; // SerialPort.SPACE_PARITY + break; + case "MARK": + parity = 4; // SerialPort.MARK_PARITY + break; + default: + parity = 0; // SerialPort.NO_PARITY + break; + } + serialPort.setComPortParameters( + Integer.parseInt(serPortSpeed.getValue()), + Integer.parseInt(serPortDataBit.getValue()), + Integer.parseInt(serPortStopBit.getValue()), + parity + );
572-587
: 未使用的监听器类
serialPortDataListener
类已定义但未在代码中使用。这个监听器应用于接收串口数据,但当前没有将其注册到任何串口实例上。建议在打开串口后添加此监听器,以实现数据接收功能:
serialPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_BLOCKING | SerialPort.TIMEOUT_WRITE_BLOCKING, 1000, 1000); + // 添加数据接收监听器 + serialPort.addDataListener(new serialPortDataListener());同时,应修改
serialEvent
方法将接收到的数据显示到recvTextAear
文本区域,并支持十六进制显示模式。
573-587
: 内部类命名不符合Java命名规范内部类
serialPortDataListener
的命名不符合Java的命名规范,类名应使用驼峰式命名法并以大写字母开头。- private final static class serialPortDataListener implements SerialPortDataListener { + private final static class SerialPortDataListener implements SerialPortDataListener {
623-636
: 优化十六进制转换方法当前的
bytesToHexString
方法使用了StringBuffer
,但没有预设容量,可能导致多次扩容,影响性能。此外,方法可以更简洁。public String bytesToHexString(byte[] bArray) { if (bArray == null) { return null; } - StringBuffer sb = new StringBuffer(bArray.length); + StringBuffer sb = new StringBuffer(bArray.length * 2); // 预设足够容量,每个字节占两个字符 String sTemp; for (int i = 0; i < bArray.length; i++) { sTemp = Integer.toHexString(0xFF & bArray[i]); if (sTemp.length() < 2) { sb.append(0); } sb.append(sTemp.toUpperCase()); + // 可选:每个字节后添加空格,提高可读性 + if (i < bArray.length - 1) { + sb.append(" "); + } } return sb.toString(); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
qe/src/main/java/com/tlcsdm/qe/tools/SerialPortTool.java
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: qodana
- GitHub Check: build (17, ubuntu-latest, false)
- GitHub Check: build (17, windows-latest, false)
- GitHub Check: build (21, windows-latest, false)
- GitHub Check: build (21, macos-latest, false)
- GitHub Check: build (21, ubuntu-latest, false)
- GitHub Check: build (17, macos-latest, false)
- GitHub Check: Summary
🔇 Additional comments (5)
qe/src/main/java/com/tlcsdm/qe/tools/SerialPortTool.java (5)
75-89
: 新增串口参数选择器,增强了用户界面功能为串口配置添加了更全面的选择器,包括波特率、校验位、数据位和停止位,使用户能够更精确地配置串口通信参数。
93-94
: 增加16进制显示切换功能添加了16进制接收显示开关,对于需要查看二进制数据的场景非常实用。
282-316
: 完善的串口参数初始化设置参数选择器的初始化代码结构清晰,提供了全面的串口配置选项:
- 波特率选项覆盖了从100到256000的广泛范围
- 校验位包含所有常见选项(NONE, ODD, EVEN, MARK, SPACE)
- 数据位和停止位设置完备
设置的默认值(9600波特率,无校验位,8数据位,1停止位)符合串口通信的常见配置。
342-342
: 删除了未使用的方法调用移除了之前代码中的空行或注释代码,这是良好的代码清理实践。
353-355
: API方法名称更新在注释代码中,将
serialPort.isOpened()
更新为serialPort.isOpen()
,符合jSerialComm库的API命名规范。
@unknowIfGuestInDream |
3 similar comments
@unknowIfGuestInDream |
@unknowIfGuestInDream |
@unknowIfGuestInDream |
98f4f4c
to
b7a25d8
Compare
b7a25d8
to
e3b1180
Compare
@unknowIfGuestInDream |
1 similar comment
@unknowIfGuestInDream |
@unknowIfGuestInDream |
@unknowIfGuestInDream |
4 similar comments
@unknowIfGuestInDream |
@unknowIfGuestInDream |
@unknowIfGuestInDream |
@unknowIfGuestInDream |
Signed-off-by: 梦里不知身是客 <liang.tang.cx@gmail.com>
Thank you for following naming conventions! 😻 |
Qodana Community for JVMIt seems all right 👌 No new problems were found according to the checks applied 💡 Qodana analysis was run in the pull request mode: only the changed files were checked Contact Qodana teamContact us at qodana-support@jetbrains.com
|
@unknowIfGuestInDream |
3 similar comments
@unknowIfGuestInDream |
@unknowIfGuestInDream |
@unknowIfGuestInDream |
|
Qodana Community for JVMIt seems all right 👌 No new problems were found according to the checks applied 💡 Qodana analysis was run in the pull request mode: only the changed files were checked Contact Qodana teamContact us at qodana-support@jetbrains.com
|
Close #1900
Fixes #
Proposed Changes
Readiness Checklist
Author/Contributor
Reviewing Maintainer
enhancement
,bug
,documentation
ordependencies
Summary by Sourcery
Add jSerialComm library to project dependencies for improved serial port communication support
New Features:
Enhancements:
Summary by CodeRabbit