From 08034e970e6eeb5746e4e80a9b8612a5275ff8cd Mon Sep 17 00:00:00 2001 From: Josh Pieper Date: Sat, 5 Jun 2021 09:12:28 -0400 Subject: [PATCH] Support recording device uuid --- fw/BUILD | 1 + fw/power_dist.cc | 2 ++ fw/uuid.h | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 fw/uuid.h diff --git a/fw/BUILD b/fw/BUILD index 3c1919c..54e0e35 100644 --- a/fw/BUILD +++ b/fw/BUILD @@ -49,6 +49,7 @@ mbed_binary( "power_dist.cc", "power_dist_hw.h", "stm32g4_flash.h", + "uuid.h", ], deps = [ ":git_info", diff --git a/fw/power_dist.cc b/fw/power_dist.cc index d0a01b4..12f608e 100644 --- a/fw/power_dist.cc +++ b/fw/power_dist.cc @@ -35,6 +35,7 @@ #include "fw/millisecond_timer.h" #include "fw/power_dist_hw.h" #include "fw/stm32g4_flash.h" +#include "fw/uuid.h" namespace base = mjlib::base; namespace micro = mjlib::micro; @@ -916,6 +917,7 @@ class PowerDist : public mjlib::multiplex::MicroServer::Server { fw::Stm32G4Flash flash_interface_; micro::PersistentConfig persistent_config_{ pool_, command_manager_, flash_interface_}; + fw::Uuid uuid_{persistent_config_}; fw::GitInfo git_info_; fw::FirmwareInfo firmware_info_{pool_, telemetry_manager_, 0, 0}; diff --git a/fw/uuid.h b/fw/uuid.h new file mode 100644 index 0000000..25ef523 --- /dev/null +++ b/fw/uuid.h @@ -0,0 +1,39 @@ +// Copyright 2021 Josh Pieper, jjp@pobox.com. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include + +namespace fw { + +class Uuid { + public: + Uuid(mjlib::micro::PersistentConfig& config) { + config.Register("uuid", &data_, [](){}); + } + + struct Data { + std::array uuid = {}; + + template + void Serialize(Archive* a) { + a->Visit(MJ_NVP(uuid)); + } + }; + + Data data_; +}; + +}