diff --git a/protobufs b/protobufs index 1d0b4dd24..ff26da703 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 1d0b4dd242ae38b844510d4517cfdceeed294cce +Subproject commit ff26da70385fc067af3c0d2950e97f90d632f142 diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 5c28f5261..e03f9bb17 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -11,7 +11,6 @@ #include "RTC.h" #include "Router.h" #include "error.h" -#include "main.h" #include "mesh-pb-constants.h" #include #include diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index a6fbd9cb0..7d95062a2 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -1,6 +1,7 @@ #pragma once #include "Observer.h" +#include "main.h" #include #include @@ -229,3 +230,18 @@ extern uint32_t radioGeneration; (ModuleConfig_CannedMessageConfig_size + ModuleConfig_ExternalNotificationConfig_size + ModuleConfig_MQTTConfig_size + \ ModuleConfig_RangeTestConfig_size + ModuleConfig_SerialConfig_size + ModuleConfig_StoreForwardConfig_size + \ ModuleConfig_TelemetryConfig_size + ModuleConfig_size) + +inline meshtastic_DeviceMetadata getDeviceMetadata() +{ + meshtastic_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; + deviceMetadata.role = config.device.role; + deviceMetadata.position_flags = config.position.position_flags; + deviceMetadata.hw_model = HW_VENDOR; + return deviceMetadata; +} \ No newline at end of file diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index 0c430ea5c..c91863bdc 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -277,11 +277,15 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) config_state++; // Advance when we have sent all of our ModuleConfig objects if (config_state > (_meshtastic_AdminMessage_ModuleConfigType_MAX + 1)) { - state = STATE_SEND_COMPLETE_ID; + state = STATE_SEND_METADATA; config_state = 0; } break; - + case STATE_SEND_METADATA: + fromRadioScratch.which_payload_variant = meshtastic_FromRadio_metadata_tag; + fromRadioScratch.metadata = getDeviceMetadata(); + state = STATE_SEND_COMPLETE_ID; + break; case STATE_SEND_COMPLETE_ID: LOG_INFO("getFromRadio=STATE_SEND_COMPLETE_ID\n"); fromRadioScratch.which_payload_variant = meshtastic_FromRadio_config_complete_id_tag; diff --git a/src/mesh/PhoneAPI.h b/src/mesh/PhoneAPI.h index 5a73f5874..cc219b690 100644 --- a/src/mesh/PhoneAPI.h +++ b/src/mesh/PhoneAPI.h @@ -27,6 +27,7 @@ class PhoneAPI STATE_SEND_CONFIG, // Replacement for the old Radioconfig STATE_SEND_MODULECONFIG, // Send Module specific config STATE_SEND_COMPLETE_ID, + STATE_SEND_METADATA, STATE_SEND_PACKETS // send packets or debug strings }; diff --git a/src/mesh/generated/meshtastic/admin.pb.h b/src/mesh/generated/meshtastic/admin.pb.h index 5995d70f7..a9c415992 100644 --- a/src/mesh/generated/meshtastic/admin.pb.h +++ b/src/mesh/generated/meshtastic/admin.pb.h @@ -6,7 +6,6 @@ #include #include "meshtastic/channel.pb.h" #include "meshtastic/config.pb.h" -#include "meshtastic/device_metadata.pb.h" #include "meshtastic/mesh.pb.h" #include "meshtastic/module_config.pb.h" #include "meshtastic/connection_status.pb.h" diff --git a/src/mesh/generated/meshtastic/mesh.pb.c b/src/mesh/generated/meshtastic/mesh.pb.c index 977e3916f..0c3c155f6 100644 --- a/src/mesh/generated/meshtastic/mesh.pb.c +++ b/src/mesh/generated/meshtastic/mesh.pb.c @@ -48,6 +48,9 @@ PB_BIND(meshtastic_ToRadio, meshtastic_ToRadio, 2) PB_BIND(meshtastic_Compressed, meshtastic_Compressed, AUTO) +PB_BIND(meshtastic_DeviceMetadata, meshtastic_DeviceMetadata, AUTO) + + diff --git a/src/mesh/generated/meshtastic/mesh.pb.h b/src/mesh/generated/meshtastic/mesh.pb.h index 0a8cf5cfe..f22294a2e 100644 --- a/src/mesh/generated/meshtastic/mesh.pb.h +++ b/src/mesh/generated/meshtastic/mesh.pb.h @@ -87,6 +87,8 @@ typedef enum _meshtastic_HardwareModel { meshtastic_HardwareModel_HELTEC_WSL_V3 = 44, /* New BETAFPV ELRS Micro TX Module 2.4G with ESP32 CPU */ meshtastic_HardwareModel_BETAFPV_2400_TX = 45, + /* BetaFPV ExpressLRS "Nano" TX Module 900MHz with ESP32 CPU */ + meshtastic_HardwareModel_BETAFPV_900_NANO_TX = 46, /* Reserved ID For developing private Ports. These will show up in live traffic sparsely, so we can use a high number. Keep it within 8 bits. */ meshtastic_HardwareModel_PRIVATE_HW = 255 } meshtastic_HardwareModel; @@ -637,6 +639,61 @@ typedef struct _meshtastic_QueueStatus { uint32_t mesh_packet_id; } meshtastic_QueueStatus; +/* Packets/commands to the radio will be written (reliably) to the toRadio characteristic. + Once the write completes the phone can assume it is handled. */ +typedef struct _meshtastic_ToRadio { + pb_size_t which_payload_variant; + union { + /* Send this packet on the mesh */ + meshtastic_MeshPacket packet; + /* Phone wants radio to send full node db to the phone, This is + typically the first packet sent to the radio when the phone gets a + bluetooth connection. The radio will respond by sending back a + MyNodeInfo, a owner, a radio config and a series of + FromRadio.node_infos, and config_complete + the integer you write into this field will be reported back in the + config_complete_id response this allows clients to never be confused by + a stale old partially sent config. */ + uint32_t want_config_id; + /* Tell API server we are disconnecting now. + This is useful for serial links where there is no hardware/protocol based notification that the client has dropped the link. + (Sending this message is optional for clients) */ + bool disconnect; + meshtastic_XModem xmodemPacket; + }; +} meshtastic_ToRadio; + +typedef PB_BYTES_ARRAY_T(237) meshtastic_Compressed_data_t; +/* Compressed message payload */ +typedef struct _meshtastic_Compressed { + /* PortNum to determine the how to handle the compressed payload. */ + meshtastic_PortNum portnum; + /* Compressed data. */ + meshtastic_Compressed_data_t data; +} meshtastic_Compressed; + +/* Device metadata response */ +typedef struct _meshtastic_DeviceMetadata { + /* Device firmware version string */ + 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; + /* Indicates that the device's role in the mesh */ + meshtastic_Config_DeviceConfig_Role role; + /* Indicates the device's current enabled position flags */ + uint32_t position_flags; + /* Device hardware model */ + meshtastic_HardwareModel hw_model; +} meshtastic_DeviceMetadata; + /* Packets from the radio to the phone will appear on the fromRadio characteristic. It will support READ and NOTIFY. When a new packet arrives the device will BLE notify? It will sit in that descriptor until consumed by the phone, @@ -677,42 +734,11 @@ typedef struct _meshtastic_FromRadio { meshtastic_QueueStatus queueStatus; /* File Transfer Chunk */ meshtastic_XModem xmodemPacket; + /* Device metadata message */ + meshtastic_DeviceMetadata metadata; }; } meshtastic_FromRadio; -/* Packets/commands to the radio will be written (reliably) to the toRadio characteristic. - Once the write completes the phone can assume it is handled. */ -typedef struct _meshtastic_ToRadio { - pb_size_t which_payload_variant; - union { - /* Send this packet on the mesh */ - meshtastic_MeshPacket packet; - /* Phone wants radio to send full node db to the phone, This is - typically the first packet sent to the radio when the phone gets a - bluetooth connection. The radio will respond by sending back a - MyNodeInfo, a owner, a radio config and a series of - FromRadio.node_infos, and config_complete - the integer you write into this field will be reported back in the - config_complete_id response this allows clients to never be confused by - a stale old partially sent config. */ - uint32_t want_config_id; - /* Tell API server we are disconnecting now. - This is useful for serial links where there is no hardware/protocol based notification that the client has dropped the link. - (Sending this message is optional for clients) */ - bool disconnect; - meshtastic_XModem xmodemPacket; - }; -} meshtastic_ToRadio; - -typedef PB_BYTES_ARRAY_T(237) meshtastic_Compressed_data_t; -/* Compressed message payload */ -typedef struct _meshtastic_Compressed { - /* PortNum to determine the how to handle the compressed payload. */ - meshtastic_PortNum portnum; - /* Compressed data. */ - meshtastic_Compressed_data_t data; -} meshtastic_Compressed; - #ifdef __cplusplus extern "C" { @@ -779,6 +805,9 @@ extern "C" { #define meshtastic_Compressed_portnum_ENUMTYPE meshtastic_PortNum +#define meshtastic_DeviceMetadata_role_ENUMTYPE meshtastic_Config_DeviceConfig_Role +#define meshtastic_DeviceMetadata_hw_model_ENUMTYPE meshtastic_HardwareModel + /* Initializer values for message structs */ #define meshtastic_Position_init_default {0, 0, 0, 0, _meshtastic_Position_LocSource_MIN, _meshtastic_Position_AltSource_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} @@ -795,6 +824,7 @@ extern "C" { #define meshtastic_FromRadio_init_default {0, 0, {meshtastic_MeshPacket_init_default}} #define meshtastic_ToRadio_init_default {0, {meshtastic_MeshPacket_init_default}} #define meshtastic_Compressed_init_default {_meshtastic_PortNum_MIN, {0, {0}}} +#define meshtastic_DeviceMetadata_init_default {"", 0, 0, 0, 0, 0, _meshtastic_Config_DeviceConfig_Role_MIN, 0, _meshtastic_HardwareModel_MIN} #define meshtastic_Position_init_zero {0, 0, 0, 0, _meshtastic_Position_LocSource_MIN, _meshtastic_Position_AltSource_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_User_init_zero {"", "", "", {0}, _meshtastic_HardwareModel_MIN, 0} #define meshtastic_RouteDiscovery_init_zero {0, {0, 0, 0, 0, 0, 0, 0, 0}} @@ -809,6 +839,7 @@ extern "C" { #define meshtastic_FromRadio_init_zero {0, 0, {meshtastic_MeshPacket_init_zero}} #define meshtastic_ToRadio_init_zero {0, {meshtastic_MeshPacket_init_zero}} #define meshtastic_Compressed_init_zero {_meshtastic_PortNum_MIN, {0, {0}}} +#define meshtastic_DeviceMetadata_init_zero {"", 0, 0, 0, 0, 0, _meshtastic_Config_DeviceConfig_Role_MIN, 0, _meshtastic_HardwareModel_MIN} /* Field tags (for use in manual encoding/decoding) */ #define meshtastic_Position_latitude_i_tag 1 @@ -902,6 +933,21 @@ extern "C" { #define meshtastic_QueueStatus_free_tag 2 #define meshtastic_QueueStatus_maxlen_tag 3 #define meshtastic_QueueStatus_mesh_packet_id_tag 4 +#define meshtastic_ToRadio_packet_tag 1 +#define meshtastic_ToRadio_want_config_id_tag 3 +#define meshtastic_ToRadio_disconnect_tag 4 +#define meshtastic_ToRadio_xmodemPacket_tag 5 +#define meshtastic_Compressed_portnum_tag 1 +#define meshtastic_Compressed_data_tag 2 +#define meshtastic_DeviceMetadata_firmware_version_tag 1 +#define meshtastic_DeviceMetadata_device_state_version_tag 2 +#define meshtastic_DeviceMetadata_canShutdown_tag 3 +#define meshtastic_DeviceMetadata_hasWifi_tag 4 +#define meshtastic_DeviceMetadata_hasBluetooth_tag 5 +#define meshtastic_DeviceMetadata_hasEthernet_tag 6 +#define meshtastic_DeviceMetadata_role_tag 7 +#define meshtastic_DeviceMetadata_position_flags_tag 8 +#define meshtastic_DeviceMetadata_hw_model_tag 9 #define meshtastic_FromRadio_id_tag 1 #define meshtastic_FromRadio_packet_tag 2 #define meshtastic_FromRadio_my_info_tag 3 @@ -914,12 +960,7 @@ extern "C" { #define meshtastic_FromRadio_channel_tag 10 #define meshtastic_FromRadio_queueStatus_tag 11 #define meshtastic_FromRadio_xmodemPacket_tag 12 -#define meshtastic_ToRadio_packet_tag 1 -#define meshtastic_ToRadio_want_config_id_tag 3 -#define meshtastic_ToRadio_disconnect_tag 4 -#define meshtastic_ToRadio_xmodemPacket_tag 5 -#define meshtastic_Compressed_portnum_tag 1 -#define meshtastic_Compressed_data_tag 2 +#define meshtastic_FromRadio_metadata_tag 13 /* Struct field encoding specification for nanopb */ #define meshtastic_Position_FIELDLIST(X, a) \ @@ -1075,7 +1116,8 @@ X(a, STATIC, ONEOF, BOOL, (payload_variant,rebooted,rebooted), 8) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,moduleConfig,moduleConfig), 9) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,channel,channel), 10) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,queueStatus,queueStatus), 11) \ -X(a, STATIC, ONEOF, MESSAGE, (payload_variant,xmodemPacket,xmodemPacket), 12) +X(a, STATIC, ONEOF, MESSAGE, (payload_variant,xmodemPacket,xmodemPacket), 12) \ +X(a, STATIC, ONEOF, MESSAGE, (payload_variant,metadata,metadata), 13) #define meshtastic_FromRadio_CALLBACK NULL #define meshtastic_FromRadio_DEFAULT NULL #define meshtastic_FromRadio_payload_variant_packet_MSGTYPE meshtastic_MeshPacket @@ -1087,6 +1129,7 @@ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,xmodemPacket,xmodemPacket), #define meshtastic_FromRadio_payload_variant_channel_MSGTYPE meshtastic_Channel #define meshtastic_FromRadio_payload_variant_queueStatus_MSGTYPE meshtastic_QueueStatus #define meshtastic_FromRadio_payload_variant_xmodemPacket_MSGTYPE meshtastic_XModem +#define meshtastic_FromRadio_payload_variant_metadata_MSGTYPE meshtastic_DeviceMetadata #define meshtastic_ToRadio_FIELDLIST(X, a) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,packet,packet), 1) \ @@ -1104,6 +1147,19 @@ X(a, STATIC, SINGULAR, BYTES, data, 2) #define meshtastic_Compressed_CALLBACK NULL #define meshtastic_Compressed_DEFAULT NULL +#define meshtastic_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, BOOL, canShutdown, 3) \ +X(a, STATIC, SINGULAR, BOOL, hasWifi, 4) \ +X(a, STATIC, SINGULAR, BOOL, hasBluetooth, 5) \ +X(a, STATIC, SINGULAR, BOOL, hasEthernet, 6) \ +X(a, STATIC, SINGULAR, UENUM, role, 7) \ +X(a, STATIC, SINGULAR, UINT32, position_flags, 8) \ +X(a, STATIC, SINGULAR, UENUM, hw_model, 9) +#define meshtastic_DeviceMetadata_CALLBACK NULL +#define meshtastic_DeviceMetadata_DEFAULT NULL + extern const pb_msgdesc_t meshtastic_Position_msg; extern const pb_msgdesc_t meshtastic_User_msg; extern const pb_msgdesc_t meshtastic_RouteDiscovery_msg; @@ -1118,6 +1174,7 @@ extern const pb_msgdesc_t meshtastic_QueueStatus_msg; extern const pb_msgdesc_t meshtastic_FromRadio_msg; extern const pb_msgdesc_t meshtastic_ToRadio_msg; extern const pb_msgdesc_t meshtastic_Compressed_msg; +extern const pb_msgdesc_t meshtastic_DeviceMetadata_msg; /* Defines for backwards compatibility with code written before nanopb-0.4.0 */ #define meshtastic_Position_fields &meshtastic_Position_msg @@ -1134,10 +1191,12 @@ extern const pb_msgdesc_t meshtastic_Compressed_msg; #define meshtastic_FromRadio_fields &meshtastic_FromRadio_msg #define meshtastic_ToRadio_fields &meshtastic_ToRadio_msg #define meshtastic_Compressed_fields &meshtastic_Compressed_msg +#define meshtastic_DeviceMetadata_fields &meshtastic_DeviceMetadata_msg /* Maximum encoded size of messages (where known) */ #define meshtastic_Compressed_size 243 #define meshtastic_Data_size 270 +#define meshtastic_DeviceMetadata_size 44 #define meshtastic_FromRadio_size 330 #define meshtastic_LogRecord_size 81 #define meshtastic_MeshPacket_size 321 diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index fd1b84bd2..4c50d7059 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -490,19 +490,7 @@ void AdminModule::handleGetModuleConfig(const meshtastic_MeshPacket &req, const void AdminModule::handleGetDeviceMetadata(const meshtastic_MeshPacket &req) { meshtastic_AdminMessage r = meshtastic_AdminMessage_init_default; - - meshtastic_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; - deviceMetadata.role = config.device.role; - deviceMetadata.position_flags = config.position.position_flags; - deviceMetadata.hw_model = HW_VENDOR; - - r.get_device_metadata_response = deviceMetadata; + r.get_device_metadata_response = getDeviceMetadata(); r.which_payload_variant = meshtastic_AdminMessage_get_device_metadata_response_tag; myReply = allocDataProtobuf(r); }