From 3fc3b141d7936eacadf9c734cfc9aa980ab889e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Cab=C3=A9?= Date: Sat, 10 Oct 2026 21:02:17 +0000 Subject: [PATCH] feat(platforms/common): GUIDs of boards that override the UUID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Boards that override their UUID, such as SITL and the Linux boards, only had the functions that format the GUID, while DroneCAN and Cyphal send the GUID itself to the other nodes, so these drivers couldn't be linked for them. board_get_mfguid() and board_get_px4_guid() now give the bytes that the formatting functions print. Assisted-by: Claude:opus-5.5 Signed-off-by: Benjamin Cabé --- platforms/common/board_identity.c | 25 ++++++++++++++++++++++++ platforms/common/board_identity_test.cpp | 24 +++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/platforms/common/board_identity.c b/platforms/common/board_identity.c index 483717b599d..6cde93109a8 100644 --- a/platforms/common/board_identity.c +++ b/platforms/common/board_identity.c @@ -103,4 +103,29 @@ int board_get_px4_guid_formated(char *format_buffer, int size) size -= offset; return board_get_mfguid_formated(&format_buffer[offset], size); } + +/* The bytes of each 32-bit word with the most significant first, as board_get_mfguid_formated() prints them */ +int board_get_mfguid(mfguid_t mfgid) +{ + uuid_uint32_t uuid; + board_get_uuid32(uuid); + + for (unsigned int i = 0; i < PX4_CPU_UUID_WORD32_LENGTH; i++) { + mfgid[4 * i] = (uuid[i] >> 24) & 0xff; + mfgid[4 * i + 1] = (uuid[i] >> 16) & 0xff; + mfgid[4 * i + 2] = (uuid[i] >> 8) & 0xff; + mfgid[4 * i + 3] = uuid[i] & 0xff; + } + + return PX4_CPU_MFGUID_BYTE_LENGTH; +} + +int board_get_px4_guid(px4_guid_t px4_guid) +{ + px4_guid[0] = (soc_arch_id >> 8) & 0xff; + px4_guid[1] = soc_arch_id & 0xff; + memset(&px4_guid[2], 0, PX4_GUID_BYTE_LENGTH - 2 - PX4_CPU_MFGUID_BYTE_LENGTH); + board_get_mfguid(&px4_guid[PX4_GUID_BYTE_LENGTH - PX4_CPU_MFGUID_BYTE_LENGTH]); + return PX4_GUID_BYTE_LENGTH; +} #endif diff --git a/platforms/common/board_identity_test.cpp b/platforms/common/board_identity_test.cpp index a028e9c29fd..4122cb74267 100644 --- a/platforms/common/board_identity_test.cpp +++ b/platforms/common/board_identity_test.cpp @@ -160,3 +160,27 @@ TEST(BoardIdentityTest, PX4GUIDBufferOverflow) board_get_px4_guid_formated(buf_40, sizeof(buf_40)); EXPECT_EQ(0, strncmp(groundtruth_px4_guid, buf_40, sizeof(buf_40) - 1)); } + +/** + * @brief Test that `board_get_px4_guid` and `board_get_mfguid` give the bytes of the formatted GUID + */ +TEST(BoardIdentityTest, PX4GUIDBytes) +{ + char formatted[PX4_GUID_FORMAT_SIZE]; + board_get_px4_guid_formated(formatted, sizeof(formatted)); + + px4_guid_t px4_guid; + EXPECT_EQ(PX4_GUID_BYTE_LENGTH, board_get_px4_guid(px4_guid)); + + char bytes[PX4_GUID_FORMAT_SIZE] {}; + + for (int i = 0; i < PX4_GUID_BYTE_LENGTH; i++) { + snprintf(&bytes[2 * i], sizeof(bytes) - 2 * i, "%02x", px4_guid[i]); + } + + EXPECT_STREQ(formatted, bytes); + + mfguid_t mfguid; + EXPECT_EQ(PX4_CPU_MFGUID_BYTE_LENGTH, board_get_mfguid(mfguid)); + EXPECT_EQ(0, memcmp(&px4_guid[PX4_GUID_BYTE_LENGTH - PX4_CPU_MFGUID_BYTE_LENGTH], mfguid, sizeof(mfguid))); +}