Add EEPROM EUI-48 device identity across firmware and API.

Read the factory 24AA025E48 serial after ADAU I2C boot, derive SoftAP SSID, BT name, STA hostname, and expose serialNumber on GET /api/health with graceful fallbacks.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-07 09:00:38 +02:00
co-authored by Cursor
parent 11ad6b43ad
commit cd94e36a9d
35 changed files with 999 additions and 83 deletions
@@ -0,0 +1,147 @@
/**
* @file DeviceIdentity.hpp
* @brief Per-board identity derived from the factory EUI-48 or fallbacks.
*
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
*
* Copyright 2026 Michele Bigi
* SPDX-License-Identifier: Apache-2.0
*
* @author Michele Bigi
* @date 2026-07-07
*/
#pragma once
#include "core/Eui48.hpp"
#include <optional>
#include <string>
#include <string_view>
namespace core {
/**
* @brief DeviceIdentity — SSID, Bluetooth name, hostname, and serial strings.
*
* @dname DeviceIdentity
* @return n/a (type)
* @pubstate Immutable after construction. unknown() uses documented fallbacks
* when the EEPROM read fails.
*
* @author Michele Bigi
* @date 2026-07-07
*/
class DeviceIdentity {
public:
/**
* @brief unknown — identity when the EUI-48 read fails.
*
* @dname unknown
* @return DeviceIdentity with fallback SSID and serial "unknown".
* @pubstate none
*
* @author Michele Bigi
* @date 2026-07-07
*/
[[nodiscard]] static DeviceIdentity unknown() noexcept;
/**
* @brief fromEui48 — derive network-visible names from factory EUI-48.
*
* @dname fromEui48
* @param eui Factory-programmed identifier from the 24AA025E48.
* @return DeviceIdentity with DigiRadio-<suffix> strings.
* @pubstate none
*
* @author Michele Bigi
* @date 2026-07-07
*/
[[nodiscard]] static DeviceIdentity fromEui48(Eui48 eui);
/**
* @brief isKnown — whether a factory EUI-48 was read successfully.
*
* @dname isKnown
* @return true when fromEui48 was used.
* @pubstate reads eui_.
*
* @author Michele Bigi
* @date 2026-07-07
*/
[[nodiscard]] bool isKnown() const noexcept;
/**
* @brief serialNumber — canonical serial or "unknown".
*
* @dname serialNumber
* @return Uppercase hex serial when known.
* @pubstate reads serialNumber_.
*
* @author Michele Bigi
* @date 2026-07-07
*/
[[nodiscard]] std::string_view serialNumber() const noexcept;
/**
* @brief softApSsid — setup SoftAP SSID for this unit.
*
* @dname softApSsid
* @return DigiRadio-<suffix> or the DigiRadio-setup fallback.
* @pubstate reads softApSsid_.
*
* @author Michele Bigi
* @date 2026-07-07
*/
[[nodiscard]] std::string_view softApSsid() const noexcept;
/**
* @brief bluetoothName — GAP friendly name for the BT1035 module.
*
* @dname bluetoothName
* @return DigiRadio-<suffix> or plain DigiRadio when unknown.
* @pubstate reads bluetoothName_.
*
* @author Michele Bigi
* @date 2026-07-07
*/
[[nodiscard]] std::string_view bluetoothName() const noexcept;
/**
* @brief hostname — STA hostname / mDNS label (no .local suffix).
*
* @dname hostname
* @return digiradio-<suffix> or digiradio when unknown.
* @pubstate reads hostname_.
*
* @author Michele Bigi
* @date 2026-07-07
*/
[[nodiscard]] std::string_view hostname() const noexcept;
/**
* @brief eui48 — optional factory identifier backing this identity.
*
* @dname eui48
* @return EUI-48 when known; otherwise empty.
* @pubstate reads eui_.
*
* @author Michele Bigi
* @date 2026-07-07
*/
[[nodiscard]] const std::optional<Eui48>& eui48() const noexcept;
private:
DeviceIdentity(std::optional<Eui48> eui,
std::string serialNumber,
std::string softApSsid,
std::string bluetoothName,
std::string hostname);
std::optional<Eui48> eui_;
std::string serialNumber_;
std::string softApSsid_;
std::string bluetoothName_;
std::string hostname_;
};
} // namespace core
@@ -0,0 +1,90 @@
/**
* @file Eui48.hpp
* @brief Strong type for a factory-programmed 48-bit EUI from 24AA025E48.
*
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
*
* Copyright 2026 Michele Bigi
* SPDX-License-Identifier: Apache-2.0
*
* @author Michele Bigi
* @date 2026-07-07
*/
#pragma once
#include <array>
#include <cstdint>
#include <string>
#include <string_view>
namespace core {
/**
* @brief Eui48 — immutable six-byte globally unique identifier.
*
* @dname Eui48
* @return n/a (type)
* @pubstate Owns bytes_; constructed only from a full six-byte payload.
*
* @author Michele Bigi
* @date 2026-07-07
*/
class Eui48 {
public:
/**
* @brief fromBytes — wrap a factory EUI-48 read from EEPROM.
*
* @dname fromBytes
* @param bytes Six-byte EUI-48 in datasheet order (0xFA..0xFF).
* @return Eui48 value.
* @pubstate none
*
* @author Michele Bigi
* @date 2026-07-07
*/
[[nodiscard]] static Eui48 fromBytes(
const std::array<std::uint8_t, 6>& bytes) noexcept;
/**
* @brief bytes — read the raw EUI-48 octets.
*
* @dname bytes
* @return Reference to the six stored bytes.
* @pubstate reads bytes_.
*
* @author Michele Bigi
* @date 2026-07-07
*/
[[nodiscard]] const std::array<std::uint8_t, 6>& bytes() const noexcept;
/**
* @brief serialNumber — canonical uppercase hex serial (12 digits).
*
* @dname serialNumber
* @return Serial string without separators (e.g. AABBCCDDEEFF).
* @pubstate none
*
* @author Michele Bigi
* @date 2026-07-07
*/
[[nodiscard]] std::string serialNumber() const;
/**
* @brief shortSuffix — last three bytes as six uppercase hex digits.
*
* @dname shortSuffix
* @return Suffix for SSID, Bluetooth name, and hostname.
* @pubstate none
*
* @author Michele Bigi
* @date 2026-07-07
*/
[[nodiscard]] std::string shortSuffix() const;
private:
explicit Eui48(std::array<std::uint8_t, 6> bytes) noexcept;
std::array<std::uint8_t, 6> bytes_;
};
} // namespace core
@@ -21,6 +21,8 @@
#include "core/CompanionChipStatus.hpp"
#include <optional>
#include <string>
#include <string_view>
namespace core {
@@ -71,8 +73,9 @@ public:
* @brief ok — build health response including companion-chip flags.
*
* @dname ok
* @param firmware Active firmware version to report.
* @param chips Si4684 / ADAU1701 / BT1035 boot snapshot.
* @param firmware Active firmware version to report.
* @param chips Si4684 / ADAU1701 / BT1035 boot snapshot.
* @param serialNumber Unit serial from EEPROM, or "unknown".
* @return HealthStatus with HealthState::Ok and chips populated.
* @pubstate none
*
@@ -80,7 +83,8 @@ public:
* @date 2026-07-06
*/
[[nodiscard]] static HealthStatus ok(FirmwareVersion firmware,
CompanionChipStatus chips);
CompanionChipStatus chips,
std::string_view serialNumber);
/**
* @brief state — read the health indicator.
@@ -119,15 +123,29 @@ public:
[[nodiscard]] const std::optional<CompanionChipStatus>& chips() const
noexcept;
/**
* @brief serialNumber — board serial from EEPROM or "unknown".
*
* @dname serialNumber
* @return Canonical serial string for /api/health.
* @pubstate reads serialNumber_.
*
* @author Michele Bigi
* @date 2026-07-07
*/
[[nodiscard]] std::string_view serialNumber() const noexcept;
private:
explicit HealthStatus(HealthState state, FirmwareVersion firmware);
explicit HealthStatus(HealthState state, FirmwareVersion firmware,
CompanionChipStatus chips);
CompanionChipStatus chips,
std::string serialNumber);
HealthState state_;
FirmwareVersion firmware_;
std::optional<CompanionChipStatus> chips_;
std::string serialNumber_;
};
} // namespace core
@@ -0,0 +1,50 @@
/**
* @file IDeviceIdentitySource.hpp
* @brief Port for reading per-board identity from non-volatile storage.
*
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
*
* Copyright 2026 Michele Bigi
* SPDX-License-Identifier: Apache-2.0
*
* @author Michele Bigi
* @date 2026-07-07
*/
#pragma once
#include "core/DeviceIdentity.hpp"
#include "core/IdentityError.hpp"
#include <expected>
namespace core {
/**
* @brief IDeviceIdentitySource — reads DeviceIdentity from board storage.
*
* @dname IDeviceIdentitySource
* @return n/a (type)
* @pubstate Implementations live in the imperative shell (EEPROM driver).
*
* @author Michele Bigi
* @date 2026-07-07
*/
class IDeviceIdentitySource {
public:
virtual ~IDeviceIdentitySource() = default;
/**
* @brief readDeviceIdentity — load identity from the backing store.
*
* @dname readDeviceIdentity
* @return DeviceIdentity on success, or IdentityError.
* @pubstate none
*
* @author Michele Bigi
* @date 2026-07-07
*/
[[nodiscard]] virtual std::expected<DeviceIdentity, IdentityError>
readDeviceIdentity() = 0;
};
} // namespace core
@@ -0,0 +1,32 @@
/**
* @file IdentityError.hpp
* @brief Failure causes when reading board identity from EEPROM.
*
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
*
* Copyright 2026 Michele Bigi
* SPDX-License-Identifier: Apache-2.0
*
* @author Michele Bigi
* @date 2026-07-07
*/
#pragma once
namespace core {
/**
* @brief IdentityError — EEPROM / I2C identity read failures.
*
* @dname IdentityError
* @return n/a (type)
* @pubstate n/a
*
* @author Michele Bigi
* @date 2026-07-07
*/
enum class IdentityError {
I2cFailed, ///< Bus or device transaction failed.
ReadFailed, ///< Payload length or EEPROM response invalid.
};
} // namespace core