From 48475051d9ead6a20c07be084e490029424e8aa3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 17 Nov 2018 08:15:59 +1100 Subject: [PATCH] HAL_Linux: implement get_system_id() on Linux this is needed for UAVCAN dynamic node allocation --- libraries/AP_HAL_Linux/Util.cpp | 53 +++++++++++++++++++++++++++++++++ libraries/AP_HAL_Linux/Util.h | 3 ++ 2 files changed, 56 insertions(+) diff --git a/libraries/AP_HAL_Linux/Util.cpp b/libraries/AP_HAL_Linux/Util.cpp index 378ee0e2c4..25acd80913 100644 --- a/libraries/AP_HAL_Linux/Util.cpp +++ b/libraries/AP_HAL_Linux/Util.cpp @@ -93,6 +93,59 @@ uint32_t Util::available_memory(void) return 256*1024; } +#ifndef HAL_LINUX_DEFAULT_SYSTEM_ID +#define HAL_LINUX_DEFAULT_SYSTEM_ID "linux-unknown" +#endif + +/* + get a (hopefully unique) machine ID + */ +bool Util::get_system_id_unformatted(uint8_t buf[], uint8_t &len) +{ + char *cbuf = (char *)buf; + + // try first to use machine-id file. Most systems will have this + const char *paths[] = { "/etc/machine-id", "/var/lib/dbus/machine-id" }; + for (uint8_t i=0; i