From 8c9e9bd4159fe87a67514e981512d7f8325318fa Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 17 Nov 2018 08:32:38 +1100 Subject: [PATCH] HAL_SITL: implement get_system_id() --- libraries/AP_HAL_SITL/Util.cpp | 48 ++++++++++++++++++++++++++++++++++ libraries/AP_HAL_SITL/Util.h | 3 +++ 2 files changed, 51 insertions(+) diff --git a/libraries/AP_HAL_SITL/Util.cpp b/libraries/AP_HAL_SITL/Util.cpp index 00c34de66e..be0bade419 100644 --- a/libraries/AP_HAL_SITL/Util.cpp +++ b/libraries/AP_HAL_SITL/Util.cpp @@ -8,3 +8,51 @@ uint64_t HALSITL::Util::get_hw_rtc() const const uint64_t nanoseconds = ts.tv_nsec; return (seconds * 1000000ULL + nanoseconds/1000ULL); } + +/* + get a (hopefully unique) machine ID + */ +bool HALSITL::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