Merge pull request #2170 from meshtastic/device-metadata-enhanced

Add role and position flags to metadata
This commit is contained in:
Ben Meadors 2023-01-18 15:16:40 -06:00 committed by GitHub
commit 48609b5bdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -109,11 +109,11 @@ bool AdminModule::handleReceivedProtobuf(const MeshPacket &mp, AdminMessage *r)
} }
case AdminMessage_reboot_ota_seconds_tag: { case AdminMessage_reboot_ota_seconds_tag: {
int32_t s = r->reboot_ota_seconds; int32_t s = r->reboot_ota_seconds;
#ifdef ARCH_ESP32 #ifdef ARCH_ESP32
if (BleOta::getOtaAppVersion().isEmpty()) { if (BleOta::getOtaAppVersion().isEmpty()) {
LOG_INFO("No OTA firmware available, scheduling regular reboot in %d seconds\n", s); LOG_INFO("No OTA firmware available, scheduling regular reboot in %d seconds\n", s);
screen->startRebootScreen(); screen->startRebootScreen();
}else{ } else {
screen->startFirmwareUpdateScreen(); screen->startFirmwareUpdateScreen();
BleOta::switchToOtaApp(); BleOta::switchToOtaApp();
LOG_INFO("Rebooting to OTA in %d seconds\n", s); LOG_INFO("Rebooting to OTA in %d seconds\n", s);
@ -141,7 +141,8 @@ bool AdminModule::handleReceivedProtobuf(const MeshPacket &mp, AdminMessage *r)
nodeDB.factoryReset(); nodeDB.factoryReset();
reboot(DEFAULT_REBOOT_SECONDS); reboot(DEFAULT_REBOOT_SECONDS);
break; break;
} case AdminMessage_nodedb_reset_tag: { }
case AdminMessage_nodedb_reset_tag: {
LOG_INFO("Initiating node-db reset\n"); LOG_INFO("Initiating node-db reset\n");
nodeDB.resetNodes(); nodeDB.resetNodes();
reboot(DEFAULT_REBOOT_SECONDS); reboot(DEFAULT_REBOOT_SECONDS);
@ -179,7 +180,7 @@ bool AdminModule::handleReceivedProtobuf(const MeshPacket &mp, AdminMessage *r)
} }
break; break;
} }
// If asked for a response and it is not yet set, generate an 'ACK' response // If asked for a response and it is not yet set, generate an 'ACK' response
if (mp.decoded.want_response && !myReply) { if (mp.decoded.want_response && !myReply) {
myReply = allocErrorResponse(Routing_Error_NONE, &mp); myReply = allocErrorResponse(Routing_Error_NONE, &mp);
@ -213,7 +214,7 @@ void AdminModule::handleSetOwner(const User &o)
changed = 1; changed = 1;
licensed_changed = true; licensed_changed = true;
owner.is_licensed = o.is_licensed; owner.is_licensed = o.is_licensed;
config.lora.override_duty_cycle = owner.is_licensed; // override duty cycle for licensed operators config.lora.override_duty_cycle = owner.is_licensed; // override duty cycle for licensed operators
} }
if (changed) { // If nothing really changed, don't broadcast on the network or write to flash if (changed) { // If nothing really changed, don't broadcast on the network or write to flash
@ -228,106 +229,104 @@ void AdminModule::handleSetConfig(const Config &c)
bool isRegionUnset = (config.lora.region == Config_LoRaConfig_RegionCode_UNSET); bool isRegionUnset = (config.lora.region == Config_LoRaConfig_RegionCode_UNSET);
switch (c.which_payload_variant) { switch (c.which_payload_variant) {
case Config_device_tag: case Config_device_tag:
LOG_INFO("Setting config: Device\n"); LOG_INFO("Setting config: Device\n");
config.has_device = true; config.has_device = true;
config.device = c.payload_variant.device; config.device = c.payload_variant.device;
// If we're setting router role for the first time, install its intervals // If we're setting router role for the first time, install its intervals
if (!isRouter && if (!isRouter && c.payload_variant.device.role == Config_DeviceConfig_Role_ROUTER) {
c.payload_variant.device.role == Config_DeviceConfig_Role_ROUTER) { nodeDB.initConfigIntervals();
nodeDB.initConfigIntervals(); nodeDB.initModuleConfigIntervals();
nodeDB.initModuleConfigIntervals(); }
} break;
break; case Config_position_tag:
case Config_position_tag: LOG_INFO("Setting config: Position\n");
LOG_INFO("Setting config: Position\n"); config.has_position = true;
config.has_position = true; config.position = c.payload_variant.position;
config.position = c.payload_variant.position; // Save nodedb as well in case we got a fixed position packet
// Save nodedb as well in case we got a fixed position packet saveChanges(SEGMENT_DEVICESTATE, false);
saveChanges(SEGMENT_DEVICESTATE, false); break;
break; case Config_power_tag:
case Config_power_tag: LOG_INFO("Setting config: Power\n");
LOG_INFO("Setting config: Power\n"); config.has_power = true;
config.has_power = true; config.power = c.payload_variant.power;
config.power = c.payload_variant.power; break;
break; case Config_network_tag:
case Config_network_tag: LOG_INFO("Setting config: WiFi\n");
LOG_INFO("Setting config: WiFi\n"); config.has_network = true;
config.has_network = true; config.network = c.payload_variant.network;
config.network = c.payload_variant.network; break;
break; case Config_display_tag:
case Config_display_tag: LOG_INFO("Setting config: Display\n");
LOG_INFO("Setting config: Display\n"); config.has_display = true;
config.has_display = true; config.display = c.payload_variant.display;
config.display = c.payload_variant.display; break;
break; case Config_lora_tag:
case Config_lora_tag: LOG_INFO("Setting config: LoRa\n");
LOG_INFO("Setting config: LoRa\n"); config.has_lora = true;
config.has_lora = true; config.lora = c.payload_variant.lora;
config.lora = c.payload_variant.lora; if (isRegionUnset && config.lora.region > Config_LoRaConfig_RegionCode_UNSET) {
if (isRegionUnset && config.lora.tx_enabled = true;
config.lora.region > Config_LoRaConfig_RegionCode_UNSET) { }
config.lora.tx_enabled = true; break;
} case Config_bluetooth_tag:
break; LOG_INFO("Setting config: Bluetooth\n");
case Config_bluetooth_tag: config.has_bluetooth = true;
LOG_INFO("Setting config: Bluetooth\n"); config.bluetooth = c.payload_variant.bluetooth;
config.has_bluetooth = true; break;
config.bluetooth = c.payload_variant.bluetooth;
break;
} }
saveChanges(SEGMENT_CONFIG); saveChanges(SEGMENT_CONFIG);
} }
void AdminModule::handleSetModuleConfig(const ModuleConfig &c) void AdminModule::handleSetModuleConfig(const ModuleConfig &c)
{ {
switch (c.which_payload_variant) { switch (c.which_payload_variant) {
case ModuleConfig_mqtt_tag: case ModuleConfig_mqtt_tag:
LOG_INFO("Setting module config: MQTT\n"); LOG_INFO("Setting module config: MQTT\n");
moduleConfig.has_mqtt = true; moduleConfig.has_mqtt = true;
moduleConfig.mqtt = c.payload_variant.mqtt; moduleConfig.mqtt = c.payload_variant.mqtt;
break; break;
case ModuleConfig_serial_tag: case ModuleConfig_serial_tag:
LOG_INFO("Setting module config: Serial\n"); LOG_INFO("Setting module config: Serial\n");
moduleConfig.has_serial = true; moduleConfig.has_serial = true;
moduleConfig.serial = c.payload_variant.serial; moduleConfig.serial = c.payload_variant.serial;
break; break;
case ModuleConfig_external_notification_tag: case ModuleConfig_external_notification_tag:
LOG_INFO("Setting module config: External Notification\n"); LOG_INFO("Setting module config: External Notification\n");
moduleConfig.has_external_notification = true; moduleConfig.has_external_notification = true;
moduleConfig.external_notification = c.payload_variant.external_notification; moduleConfig.external_notification = c.payload_variant.external_notification;
break; break;
case ModuleConfig_store_forward_tag: case ModuleConfig_store_forward_tag:
LOG_INFO("Setting module config: Store & Forward\n"); LOG_INFO("Setting module config: Store & Forward\n");
moduleConfig.has_store_forward = true; moduleConfig.has_store_forward = true;
moduleConfig.store_forward = c.payload_variant.store_forward; moduleConfig.store_forward = c.payload_variant.store_forward;
break; break;
case ModuleConfig_range_test_tag: case ModuleConfig_range_test_tag:
LOG_INFO("Setting module config: Range Test\n"); LOG_INFO("Setting module config: Range Test\n");
moduleConfig.has_range_test = true; moduleConfig.has_range_test = true;
moduleConfig.range_test = c.payload_variant.range_test; moduleConfig.range_test = c.payload_variant.range_test;
break; break;
case ModuleConfig_telemetry_tag: case ModuleConfig_telemetry_tag:
LOG_INFO("Setting module config: Telemetry\n"); LOG_INFO("Setting module config: Telemetry\n");
moduleConfig.has_telemetry = true; moduleConfig.has_telemetry = true;
moduleConfig.telemetry = c.payload_variant.telemetry; moduleConfig.telemetry = c.payload_variant.telemetry;
break; break;
case ModuleConfig_canned_message_tag: case ModuleConfig_canned_message_tag:
LOG_INFO("Setting module config: Canned Message\n"); LOG_INFO("Setting module config: Canned Message\n");
moduleConfig.has_canned_message = true; moduleConfig.has_canned_message = true;
moduleConfig.canned_message = c.payload_variant.canned_message; moduleConfig.canned_message = c.payload_variant.canned_message;
break; break;
case ModuleConfig_audio_tag: case ModuleConfig_audio_tag:
LOG_INFO("Setting module config: Audio\n"); LOG_INFO("Setting module config: Audio\n");
moduleConfig.has_audio = true; moduleConfig.has_audio = true;
moduleConfig.audio = c.payload_variant.audio; moduleConfig.audio = c.payload_variant.audio;
break; break;
case ModuleConfig_remote_hardware_tag: case ModuleConfig_remote_hardware_tag:
LOG_INFO("Setting module config: Remote Hardware\n"); LOG_INFO("Setting module config: Remote Hardware\n");
moduleConfig.has_remote_hardware = true; moduleConfig.has_remote_hardware = true;
moduleConfig.remote_hardware = c.payload_variant.remote_hardware; moduleConfig.remote_hardware = c.payload_variant.remote_hardware;
break; break;
} }
saveChanges(SEGMENT_MODULECONFIG); saveChanges(SEGMENT_MODULECONFIG);
@ -381,7 +380,8 @@ void AdminModule::handleGetConfig(const MeshPacket &req, const uint32_t configTy
LOG_INFO("Getting config: Network\n"); LOG_INFO("Getting config: Network\n");
res.get_config_response.which_payload_variant = Config_network_tag; res.get_config_response.which_payload_variant = Config_network_tag;
res.get_config_response.payload_variant.network = config.network; res.get_config_response.payload_variant.network = config.network;
writeSecret(res.get_config_response.payload_variant.network.wifi_psk, sizeof(res.get_config_response.payload_variant.network.wifi_psk), config.network.wifi_psk); writeSecret(res.get_config_response.payload_variant.network.wifi_psk,
sizeof(res.get_config_response.payload_variant.network.wifi_psk), config.network.wifi_psk);
break; break;
case AdminMessage_ConfigType_DISPLAY_CONFIG: case AdminMessage_ConfigType_DISPLAY_CONFIG:
LOG_INFO("Getting config: Display\n"); LOG_INFO("Getting config: Display\n");
@ -430,8 +430,7 @@ void AdminModule::handleGetModuleConfig(const MeshPacket &req, const uint32_t co
case AdminMessage_ModuleConfigType_EXTNOTIF_CONFIG: case AdminMessage_ModuleConfigType_EXTNOTIF_CONFIG:
LOG_INFO("Getting module config: External Notification\n"); LOG_INFO("Getting module config: External Notification\n");
res.get_module_config_response.which_payload_variant = ModuleConfig_external_notification_tag; res.get_module_config_response.which_payload_variant = ModuleConfig_external_notification_tag;
res.get_module_config_response.payload_variant.external_notification = res.get_module_config_response.payload_variant.external_notification = moduleConfig.external_notification;
moduleConfig.external_notification;
break; break;
case AdminMessage_ModuleConfigType_STOREFORWARD_CONFIG: case AdminMessage_ModuleConfigType_STOREFORWARD_CONFIG:
LOG_INFO("Getting module config: Store & Forward\n"); LOG_INFO("Getting module config: Store & Forward\n");
@ -477,9 +476,10 @@ void AdminModule::handleGetModuleConfig(const MeshPacket &req, const uint32_t co
} }
} }
void AdminModule::handleGetDeviceMetadata(const MeshPacket &req) { void AdminModule::handleGetDeviceMetadata(const MeshPacket &req)
{
AdminMessage r = AdminMessage_init_default; AdminMessage r = AdminMessage_init_default;
DeviceMetadata deviceMetadata; DeviceMetadata deviceMetadata;
strncpy(deviceMetadata.firmware_version, myNodeInfo.firmware_version, 18); strncpy(deviceMetadata.firmware_version, myNodeInfo.firmware_version, 18);
deviceMetadata.device_state_version = DEVICESTATE_CUR_VER; deviceMetadata.device_state_version = DEVICESTATE_CUR_VER;
@ -487,6 +487,8 @@ void AdminModule::handleGetDeviceMetadata(const MeshPacket &req) {
deviceMetadata.hasBluetooth = HAS_BLUETOOTH; deviceMetadata.hasBluetooth = HAS_BLUETOOTH;
deviceMetadata.hasWifi = HAS_WIFI; deviceMetadata.hasWifi = HAS_WIFI;
deviceMetadata.hasEthernet = HAS_ETHERNET; deviceMetadata.hasEthernet = HAS_ETHERNET;
deviceMetadata.role = config.device.role;
deviceMetadata.position_flags = config.position.position_flags;
r.get_device_metadata_response = deviceMetadata; r.get_device_metadata_response = deviceMetadata;
r.which_payload_variant = AdminMessage_get_device_metadata_response_tag; r.which_payload_variant = AdminMessage_get_device_metadata_response_tag;
@ -504,14 +506,14 @@ void AdminModule::handleGetChannel(const MeshPacket &req, uint32_t channelIndex)
} }
} }
void AdminModule::reboot(int32_t seconds) void AdminModule::reboot(int32_t seconds)
{ {
LOG_INFO("Rebooting in %d seconds\n", seconds); LOG_INFO("Rebooting in %d seconds\n", seconds);
screen->startRebootScreen(); screen->startRebootScreen();
rebootAtMsec = (seconds < 0) ? 0 : (millis() + seconds * 1000); rebootAtMsec = (seconds < 0) ? 0 : (millis() + seconds * 1000);
} }
void AdminModule::saveChanges(int saveWhat, bool shouldReboot) void AdminModule::saveChanges(int saveWhat, bool shouldReboot)
{ {
if (!hasOpenEditTransaction) { if (!hasOpenEditTransaction) {
LOG_INFO("Saving changes to disk\n"); LOG_INFO("Saving changes to disk\n");
@ -519,8 +521,7 @@ void AdminModule::saveChanges(int saveWhat, bool shouldReboot)
} else { } else {
LOG_INFO("Delaying save of changes to disk until the open transaction is committed\n"); LOG_INFO("Delaying save of changes to disk until the open transaction is committed\n");
} }
if (shouldReboot) if (shouldReboot) {
{
reboot(DEFAULT_REBOOT_SECONDS); reboot(DEFAULT_REBOOT_SECONDS);
} }
} }