From 43f6c4df77d6e3f98cd00a6a469cf8112fde7bb7 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Mon, 2 Oct 2017 12:06:23 -1000 Subject: [PATCH] kinetis:Add PX4 GUID API --- .../boards/common/kinetis/board_identity.c | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/drivers/boards/common/kinetis/board_identity.c b/src/drivers/boards/common/kinetis/board_identity.c index 704e59bf55..38d4f091bd 100644 --- a/src/drivers/boards/common/kinetis/board_identity.c +++ b/src/drivers/boards/common/kinetis/board_identity.c @@ -44,6 +44,8 @@ #include #include +static const uint16_t soc_arch_id = PX4_SOC_ARCH_ID; + #define SWAP_UINT32(x) (((x) >> 24) | (((x) & 0x00ff0000) >> 8) | (((x) & 0x0000ff00) << 8) | ((x) << 24)) void board_get_uuid(uuid_byte_t uuid_bytes) @@ -102,3 +104,31 @@ int board_get_mfguid_formated(char *format_buffer, int size) return offset; } + +int board_get_px4_guid(px4_guid_t px4_guid) +{ + uint8_t *pb = (uint8_t *) &px4_guid[0]; + *pb++ = (soc_arch_id >> 8) & 0xff; + *pb++ = (soc_arch_id & 0xff); + board_get_uuid(&px4_guid[4]); + return PX4_GUID_BYTE_LENGTH; +} + +int board_get_px4_guid_formated(char *format_buffer, int size) +{ + px4_guid_t px4_guid; + board_get_px4_guid(px4_guid); + int offset = 0; + + /* size should be 2 per byte + 1 for termination + * So it needs to be odd + */ + size = size & 1 ? size : size - 1; + + /* Discard from MSD */ + for (unsigned i = PX4_GUID_BYTE_LENGTH - size / 2; offset < size && i < PX4_GUID_BYTE_LENGTH; i++) { + offset += snprintf(&format_buffer[offset], size - offset, "%02x", px4_guid[i]); + } + + return offset; +}