Skip to content

ubx: Refactor codebase in order to improve usability #89900

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

Merged

Conversation

ubieda
Copy link
Member

@ubieda ubieda commented May 13, 2025

Description

During testing and code inspection, there were various anti-patterns on this (and U-Blox driver) codebase(s), including obfuscation, and lack of data validation. This made it increasingly difficult to introduce further variants of u-blox GNSS modems and/or extend the functionality of existing ones (e.g: UBX M8).

With this patch, both the UBX modem and the M8 driver have been refactored to ease the reliability and maintainability of these codebases. Here are some highlights:

WRT UBX modem:

  • Helper macros to easily create UBX frames, (including checksum calculation), at compile time; thus, making it easier to extend UBX commands.
  • Logic validation by the inclusion of the modem_ubx testsuite, used to refactor the code through TDD.
  • Ability to receive unsolicited messages, in order to enable U-Blox drivers to rely on modem_ubx to transceive all commands, and avoid hopping between modem_ubx and modem_chat.

WRT M8 driver:

  • Remove GNSS specific protocol header files. Instead, unify them under modem/ubx/protocol.h. Background: After a survey and looking at ubxlib SDK I conclude the UBX protocol is by definition a GNSS protocol (there are non-GNSS u-blox modems, but they're not interfaced through UBX protocol).
  • Establish pattern to create and send/receive commands using new foundations on modem ubx.
  • Remove dependency of Modem chat, and instead use UBX unsolicited messages to get Navigation and Satellites data.
  • Switch from the auto-baudrate detection pattern to a pattern of transitioning between an initial known baudrate to a desired baudrate, in order to improve initialization time.
  • Add dts property to configure default fix-rate.

Testing

  • As part of the refactoring of Modem UBX, testsuite introduced passes all test-cases.
  • Also, I have a ZOE-M8Q which I've tested with GNSS sample-code and validate I'm getting valid PVT data and Satellites information. I've also validated through a Logic analyzer the transfers (cmd/rsp) follow expected pattern.

@ubieda ubieda force-pushed the gnss/ubx-codebase-refactoring branch from ddfdace to 56c629f Compare May 13, 2025 15:27
Copy link
Collaborator

@bjarki-andreasen bjarki-andreasen left a comment

Choose a reason for hiding this comment

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

Looks really good, major improvement! I would like to see the processing between UBX frames to publishing through the GNSS API be moved to a "base" context like gnss_nmea0183_match.c which could be used by more if not all UBX based GNSS modems :) This will make the m8 driver waay smaller

@ubieda ubieda force-pushed the gnss/ubx-codebase-refactoring branch 2 times, most recently from 7645795 to a3d3cbd Compare May 13, 2025 17:47
@ubieda
Copy link
Member Author

ubieda commented May 13, 2025

Pushed to address CI failures and change-request. Once CI is green I'll mark this PR as ready for final review!

@ubieda ubieda force-pushed the gnss/ubx-codebase-refactoring branch from a3d3cbd to be19fd2 Compare May 13, 2025 19:45
@ubieda ubieda marked this pull request as ready for review May 13, 2025 20:26
@ubieda ubieda requested a review from bjarki-andreasen May 13, 2025 20:27
@kartben kartben requested a review from Copilot May 13, 2025 20:55
Copilot

This comment was marked as off-topic.

@ubieda ubieda requested a review from JordanYates May 13, 2025 23:39
Copy link
Collaborator

@bjarki-andreasen bjarki-andreasen left a comment

Choose a reason for hiding this comment

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

Nice :)

During testing and code inspection, there were various anti-patterns
on this (and U-Blox driver) codebase(s), including obfuscation, and
lack of data validation. This made it increasingly difficult to
introduce further variants of u-blox GNSS modems.

With this patch, both the UBX modem and the M8 driver have been
refactored to ease the reliability and maintainability of these
codebases. Here are some highlights:

WRT UBX modem:
- Helper macros to easily create UBX frames, (including checksum
calculation), at compile time; thus, making it easier to extend UBX
commands.
- Logic validation by the inclusion of the modem_ubx testsuite, used to
refactor the code through TDD.
- Ability to receive unsolicited messages, in order to enable U-Blox
drivers to rely on modem_ubx to transceive all commands, and avoid
hopping between modem_ubx and modem_chat.

WRT M8 driver:
- Remove GNSS specific protocol header files. Instead, unify them under
modem/ubx/protocol.h. Background: After a survey and looking at ubxlib
SDK I conclude the UBX protocol is by definition a GNSS protocol (there
are non-GNSS u-blox modems, but they're not interfaced through UBX
protocol).
- Establish pattern to create and send/receive commands using new
foundations on modem ubx.
- Remove dependency of Modem chat, and instead use UBX unsolicited
messages to get Navigation and Satellites data.
- Switch from the auto-baudrate detection pattern to a pattern of
transitioning between an initial known baudrate to a desired baudrate,
in order to improve initialization time.
- Add dts property to configure default fix-rate.

Signed-off-by: Luis Ubieda <[email protected]>
@ubieda ubieda force-pushed the gnss/ubx-codebase-refactoring branch from be19fd2 to 99203b7 Compare May 16, 2025 02:21
Copy link

@tomi-font tomi-font removed their request for review May 16, 2025 07:50
@bperseghetti
Copy link
Member

bperseghetti commented May 27, 2025

@bjarki-andreasen I saw you dismissed your old review and it shows a "." was that meant to be an approval? If you wouldn't mind reviewing this one again when you get a chance it would be greatly appreciated as we would like to proceed with the follow-up PRs.

@kartben kartben merged commit 94a7f02 into zephyrproject-rtos:main May 30, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants