From 311835a2310fc108307ef8289abad06d03e336fc Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 30 Oct 2022 10:02:11 -0500 Subject: [PATCH] Implement extended device metadata (#1874) * Implement extended device metadata * HAS_BLUETOOTH should be global --- protobufs | 2 +- src/configuration.h | 8 +++++++- src/mesh/generated/device_metadata.pb.h | 24 ++++++++++++++++++++---- src/modules/AdminModule.cpp | 4 ++++ src/platform/nrf52/architecture.h | 3 +++ 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/protobufs b/protobufs index a79e3aef8..46bc0afe0 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit a79e3aef8117dad642b1a011ec0438619616740c +Subproject commit 46bc0afe050a836b6ec8b235c3ff55e9e037efcb diff --git a/src/configuration.h b/src/configuration.h index 6ad5f8ff9..4b157611d 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -143,7 +143,7 @@ along with this program. If not, see . #define HAS_WIFI 0 #endif #ifndef HAS_ETHERNET - #define ETHERNET 0 + #define HAS_ETHERNET 0 #endif #ifndef HAS_SCREEN #define HAS_SCREEN 0 @@ -166,6 +166,12 @@ along with this program. If not, see . #ifndef HAS_RTC #define HAS_RTC 0 #endif +#ifndef HAS_CPU_SHUTDOWN + #define HAS_CPU_SHUTDOWN 0 +#endif +#ifndef HAS_BLUETOOTH + #define HAS_BLUETOOTH 0 +#endif #include "RF95Configuration.h" #include "DebugConfiguration.h" diff --git a/src/mesh/generated/device_metadata.pb.h b/src/mesh/generated/device_metadata.pb.h index 7bd32979e..1f4c81c5b 100644 --- a/src/mesh/generated/device_metadata.pb.h +++ b/src/mesh/generated/device_metadata.pb.h @@ -16,6 +16,14 @@ typedef struct _DeviceMetadata { char firmware_version[18]; /* Device state version */ uint32_t device_state_version; + /* Indicates whether the device can shutdown CPU natively or via power management chip */ + bool canShutdown; + /* Indicates that the device has native wifi capability */ + bool hasWifi; + /* Indicates that the device has native bluetooth capability */ + bool hasBluetooth; + /* Indicates that the device has an ethernet peripheral */ + bool hasEthernet; } DeviceMetadata; @@ -24,17 +32,25 @@ extern "C" { #endif /* Initializer values for message structs */ -#define DeviceMetadata_init_default {"", 0} -#define DeviceMetadata_init_zero {"", 0} +#define DeviceMetadata_init_default {"", 0, 0, 0, 0, 0} +#define DeviceMetadata_init_zero {"", 0, 0, 0, 0, 0} /* Field tags (for use in manual encoding/decoding) */ #define DeviceMetadata_firmware_version_tag 1 #define DeviceMetadata_device_state_version_tag 2 +#define DeviceMetadata_canShutdown_tag 3 +#define DeviceMetadata_hasWifi_tag 4 +#define DeviceMetadata_hasBluetooth_tag 5 +#define DeviceMetadata_hasEthernet_tag 6 /* Struct field encoding specification for nanopb */ #define DeviceMetadata_FIELDLIST(X, a) \ X(a, STATIC, SINGULAR, STRING, firmware_version, 1) \ -X(a, STATIC, SINGULAR, UINT32, device_state_version, 2) +X(a, STATIC, SINGULAR, UINT32, device_state_version, 2) \ +X(a, STATIC, SINGULAR, BOOL, canShutdown, 3) \ +X(a, STATIC, SINGULAR, BOOL, hasWifi, 4) \ +X(a, STATIC, SINGULAR, BOOL, hasBluetooth, 5) \ +X(a, STATIC, SINGULAR, BOOL, hasEthernet, 6) #define DeviceMetadata_CALLBACK NULL #define DeviceMetadata_DEFAULT NULL @@ -44,7 +60,7 @@ extern const pb_msgdesc_t DeviceMetadata_msg; #define DeviceMetadata_fields &DeviceMetadata_msg /* Maximum encoded size of messages (where known) */ -#define DeviceMetadata_size 25 +#define DeviceMetadata_size 33 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 6a10c618a..16ce47cec 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -441,6 +441,10 @@ void AdminModule::handleGetDeviceMetadata(const MeshPacket &req) { DeviceMetadata deviceMetadata; strncpy(deviceMetadata.firmware_version, myNodeInfo.firmware_version, 18); deviceMetadata.device_state_version = DEVICESTATE_CUR_VER; + deviceMetadata.canShutdown = pmu_found || HAS_CPU_SHUTDOWN; + deviceMetadata.hasBluetooth = HAS_BLUETOOTH; + deviceMetadata.hasWifi = HAS_WIFI; + deviceMetadata.hasEthernet = HAS_ETHERNET; r.get_device_metadata_response = deviceMetadata; r.which_payload_variant = AdminMessage_get_device_metadata_response_tag; diff --git a/src/platform/nrf52/architecture.h b/src/platform/nrf52/architecture.h index 63e173434..47d95c92d 100644 --- a/src/platform/nrf52/architecture.h +++ b/src/platform/nrf52/architecture.h @@ -26,6 +26,9 @@ #ifndef HAS_RADIO #define HAS_RADIO 1 #endif +#ifdef HAS_CPU_SHUTDOWN + #define HAS_CPU_SHUTDOWN 1 +#endif // // set HW_VENDOR