2022-02-27 08:18:35 +00:00
|
|
|
#include "AdminModule.h"
|
2021-02-26 07:34:00 +00:00
|
|
|
#include "Channels.h"
|
2021-02-21 06:03:44 +00:00
|
|
|
#include "MeshService.h"
|
|
|
|
#include "NodeDB.h"
|
|
|
|
#include "Router.h"
|
2022-05-01 22:53:44 +00:00
|
|
|
#include "configuration.h"
|
2021-02-21 06:03:44 +00:00
|
|
|
#include "main.h"
|
|
|
|
|
2022-07-31 12:11:47 +00:00
|
|
|
#ifdef ARCH_PORTDUINO
|
2021-03-18 11:09:31 +00:00
|
|
|
#include "unistd.h"
|
|
|
|
#endif
|
|
|
|
|
2022-02-27 10:21:02 +00:00
|
|
|
AdminModule *adminModule;
|
2021-02-21 06:03:44 +00:00
|
|
|
|
2021-08-01 18:21:36 +00:00
|
|
|
/// A special reserved string to indicate strings we can not share with external nodes. We will use this 'reserved' word instead.
|
2022-05-01 22:53:44 +00:00
|
|
|
/// Also, to make setting work correctly, if someone tries to set a string to this reserved value we assume they don't really want
|
|
|
|
/// a change.
|
2021-08-01 18:21:36 +00:00
|
|
|
static const char *secretReserved = "sekrit";
|
|
|
|
|
|
|
|
/// If buf is the reserved secret word, replace the buffer with currentVal
|
2022-05-01 22:53:44 +00:00
|
|
|
static void writeSecret(char *buf, const char *currentVal)
|
|
|
|
{
|
|
|
|
if (strcmp(buf, secretReserved) == 0) {
|
2021-08-01 18:21:36 +00:00
|
|
|
strcpy(buf, currentVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-02 12:00:24 +00:00
|
|
|
/**
|
|
|
|
* @brief Handle recieved protobuf message
|
|
|
|
*
|
|
|
|
* @param mp Recieved MeshPacket
|
|
|
|
* @param r Decoded AdminMessage
|
|
|
|
* @return bool
|
|
|
|
*/
|
2022-02-27 10:21:02 +00:00
|
|
|
bool AdminModule::handleReceivedProtobuf(const MeshPacket &mp, AdminMessage *r)
|
2021-02-21 06:03:44 +00:00
|
|
|
{
|
2022-02-21 05:29:15 +00:00
|
|
|
// if handled == false, then let others look at this message also if they want
|
|
|
|
bool handled = false;
|
2021-02-21 06:03:44 +00:00
|
|
|
assert(r);
|
2022-05-02 12:00:24 +00:00
|
|
|
|
2021-02-26 07:34:00 +00:00
|
|
|
switch (r->which_variant) {
|
2022-05-02 12:00:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Getters
|
|
|
|
*/
|
|
|
|
case AdminMessage_get_owner_request_tag:
|
|
|
|
DEBUG_MSG("Client is getting owner\n");
|
|
|
|
handleGetOwner(mp);
|
2021-02-26 07:34:00 +00:00
|
|
|
break;
|
|
|
|
|
2022-05-02 12:00:24 +00:00
|
|
|
case AdminMessage_get_config_request_tag:
|
|
|
|
DEBUG_MSG("Client is getting config\n");
|
2022-05-29 14:31:30 +00:00
|
|
|
handleGetConfig(mp, r->get_config_request);
|
2022-05-02 12:00:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AdminMessage_get_module_config_request_tag:
|
|
|
|
DEBUG_MSG("Client is getting module config\n");
|
2022-05-03 12:16:50 +00:00
|
|
|
handleGetModuleConfig(mp, r->get_module_config_request);
|
2021-02-26 07:34:00 +00:00
|
|
|
break;
|
|
|
|
|
2021-03-23 03:44:51 +00:00
|
|
|
case AdminMessage_get_channel_request_tag: {
|
|
|
|
uint32_t i = r->get_channel_request - 1;
|
2021-03-23 03:54:53 +00:00
|
|
|
DEBUG_MSG("Client is getting channel %u\n", i);
|
2021-03-23 03:44:51 +00:00
|
|
|
if (i >= MAX_NUM_CHANNELS)
|
2021-04-06 02:34:23 +00:00
|
|
|
myReply = allocErrorResponse(Routing_Error_BAD_REQUEST, &mp);
|
2021-03-23 03:44:51 +00:00
|
|
|
else
|
|
|
|
handleGetChannel(mp, i);
|
2021-02-26 07:34:00 +00:00
|
|
|
break;
|
2021-03-23 03:44:51 +00:00
|
|
|
}
|
2021-02-26 07:34:00 +00:00
|
|
|
|
2022-05-02 12:00:24 +00:00
|
|
|
/**
|
|
|
|
* Setters
|
|
|
|
*/
|
|
|
|
case AdminMessage_set_owner_tag:
|
|
|
|
DEBUG_MSG("Client is setting owner\n");
|
|
|
|
handleSetOwner(r->set_owner);
|
2021-02-26 07:34:00 +00:00
|
|
|
break;
|
|
|
|
|
2022-05-01 22:53:44 +00:00
|
|
|
case AdminMessage_set_config_tag:
|
|
|
|
DEBUG_MSG("Client is setting the config\n");
|
|
|
|
handleSetConfig(r->set_config);
|
|
|
|
break;
|
|
|
|
|
2022-05-02 12:00:24 +00:00
|
|
|
case AdminMessage_set_module_config_tag:
|
|
|
|
DEBUG_MSG("Client is setting the module config\n");
|
|
|
|
handleSetModuleConfig(r->set_module_config);
|
2022-03-09 22:14:56 +00:00
|
|
|
break;
|
|
|
|
|
2022-05-02 12:00:24 +00:00
|
|
|
case AdminMessage_set_channel_tag:
|
|
|
|
DEBUG_MSG("Client is setting channel %d\n", r->set_channel.index);
|
|
|
|
if (r->set_channel.index < 0 || r->set_channel.index >= (int)MAX_NUM_CHANNELS)
|
|
|
|
myReply = allocErrorResponse(Routing_Error_BAD_REQUEST, &mp);
|
|
|
|
else
|
|
|
|
handleSetChannel(r->set_channel);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Other
|
|
|
|
*/
|
2021-03-27 02:19:59 +00:00
|
|
|
case AdminMessage_reboot_seconds_tag: {
|
|
|
|
int32_t s = r->reboot_seconds;
|
|
|
|
DEBUG_MSG("Rebooting in %d seconds\n", s);
|
|
|
|
rebootAtMsec = (s < 0) ? 0 : (millis() + s * 1000);
|
|
|
|
break;
|
|
|
|
}
|
2022-01-21 21:03:26 +00:00
|
|
|
case AdminMessage_shutdown_seconds_tag: {
|
|
|
|
int32_t s = r->shutdown_seconds;
|
|
|
|
DEBUG_MSG("Shutdown in %d seconds\n", s);
|
|
|
|
shutdownAtMsec = (s < 0) ? 0 : (millis() + s * 1000);
|
|
|
|
break;
|
|
|
|
}
|
2022-08-08 12:19:04 +00:00
|
|
|
case AdminMessage_get_device_metadata_request_tag: {
|
|
|
|
DEBUG_MSG("Client is getting device metadata\n");
|
|
|
|
handleGetDeviceMetadata(mp);
|
|
|
|
break;
|
|
|
|
}
|
2021-03-27 02:19:59 +00:00
|
|
|
|
2022-07-31 12:11:47 +00:00
|
|
|
#ifdef ARCH_PORTDUINO
|
2021-03-18 11:09:31 +00:00
|
|
|
case AdminMessage_exit_simulator_tag:
|
2021-03-18 11:40:00 +00:00
|
|
|
DEBUG_MSG("Exiting simulator\n");
|
2021-03-18 11:09:31 +00:00
|
|
|
_exit(0);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2021-02-26 07:34:00 +00:00
|
|
|
default:
|
2022-05-03 12:16:50 +00:00
|
|
|
AdminMessage res = AdminMessage_init_default;
|
|
|
|
AdminMessageHandleResult handleResult = MeshModule::handleAdminMessageForAllPlugins(mp, r, &res);
|
2022-02-21 05:29:15 +00:00
|
|
|
|
2022-05-01 22:53:44 +00:00
|
|
|
if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) {
|
2022-05-03 12:16:50 +00:00
|
|
|
myReply = allocDataProtobuf(res);
|
2022-05-01 22:53:44 +00:00
|
|
|
} else if (mp.decoded.want_response) {
|
2022-02-21 05:29:15 +00:00
|
|
|
DEBUG_MSG("We did not responded to a request that wanted a respond. req.variant=%d\n", r->which_variant);
|
2022-05-01 22:53:44 +00:00
|
|
|
} else if (handleResult != AdminMessageHandleResult::HANDLED) {
|
2022-02-21 05:29:15 +00:00
|
|
|
// Probably a message sent by us or sent to our local node. FIXME, we should avoid scanning these messages
|
|
|
|
DEBUG_MSG("Ignoring nonrelevant admin %d\n", r->which_variant);
|
|
|
|
}
|
2021-02-26 07:34:00 +00:00
|
|
|
break;
|
2021-02-21 06:03:44 +00:00
|
|
|
}
|
2022-02-21 05:29:15 +00:00
|
|
|
return handled;
|
2021-02-21 06:03:44 +00:00
|
|
|
}
|
|
|
|
|
2022-05-02 12:00:24 +00:00
|
|
|
/**
|
|
|
|
* Setter methods
|
|
|
|
*/
|
|
|
|
|
2022-02-27 10:21:02 +00:00
|
|
|
void AdminModule::handleSetOwner(const User &o)
|
2021-02-21 06:03:44 +00:00
|
|
|
{
|
|
|
|
int changed = 0;
|
|
|
|
|
|
|
|
if (*o.long_name) {
|
|
|
|
changed |= strcmp(owner.long_name, o.long_name);
|
|
|
|
strcpy(owner.long_name, o.long_name);
|
|
|
|
}
|
|
|
|
if (*o.short_name) {
|
|
|
|
changed |= strcmp(owner.short_name, o.short_name);
|
|
|
|
strcpy(owner.short_name, o.short_name);
|
|
|
|
}
|
|
|
|
if (*o.id) {
|
|
|
|
changed |= strcmp(owner.id, o.id);
|
|
|
|
strcpy(owner.id, o.id);
|
|
|
|
}
|
2021-04-10 03:39:13 +00:00
|
|
|
if (owner.is_licensed != o.is_licensed) {
|
2021-11-02 13:27:56 +00:00
|
|
|
changed = 1;
|
2021-04-10 03:39:13 +00:00
|
|
|
owner.is_licensed = o.is_licensed;
|
|
|
|
}
|
2021-02-21 06:03:44 +00:00
|
|
|
|
|
|
|
if (changed) // If nothing really changed, don't broadcast on the network or write to flash
|
|
|
|
service.reloadOwner();
|
|
|
|
}
|
|
|
|
|
2022-05-02 00:24:28 +00:00
|
|
|
void AdminModule::handleSetConfig(const Config &c)
|
2022-05-01 22:53:44 +00:00
|
|
|
{
|
2022-08-22 21:41:23 +00:00
|
|
|
bool requiresReboot = false;
|
2022-05-01 22:53:44 +00:00
|
|
|
switch (c.which_payloadVariant) {
|
2022-08-22 21:41:23 +00:00
|
|
|
case Config_device_tag:
|
|
|
|
DEBUG_MSG("Setting config: Device\n");
|
|
|
|
config.has_device = true;
|
|
|
|
config.device = c.payloadVariant.device;
|
|
|
|
break;
|
|
|
|
case Config_position_tag:
|
|
|
|
DEBUG_MSG("Setting config: Position\n");
|
|
|
|
config.has_position = true;
|
|
|
|
config.position = c.payloadVariant.position;
|
|
|
|
break;
|
|
|
|
case Config_power_tag:
|
|
|
|
DEBUG_MSG("Setting config: Power\n");
|
|
|
|
config.has_power = true;
|
|
|
|
config.power = c.payloadVariant.power;
|
|
|
|
break;
|
|
|
|
case Config_wifi_tag:
|
|
|
|
DEBUG_MSG("Setting config: WiFi\n");
|
|
|
|
config.has_wifi = true;
|
|
|
|
config.wifi = c.payloadVariant.wifi;
|
2022-09-06 19:06:44 +00:00
|
|
|
requiresReboot = true;
|
2022-08-22 21:41:23 +00:00
|
|
|
break;
|
|
|
|
case Config_display_tag:
|
|
|
|
DEBUG_MSG("Setting config: Display\n");
|
|
|
|
config.has_display = true;
|
|
|
|
config.display = c.payloadVariant.display;
|
|
|
|
break;
|
|
|
|
case Config_lora_tag:
|
|
|
|
DEBUG_MSG("Setting config: LoRa\n");
|
|
|
|
config.has_lora = true;
|
|
|
|
config.lora = c.payloadVariant.lora;
|
|
|
|
requiresReboot = true;
|
|
|
|
break;
|
|
|
|
case Config_bluetooth_tag:
|
|
|
|
DEBUG_MSG("Setting config: Bluetooth\n");
|
|
|
|
config.has_bluetooth = true;
|
|
|
|
config.bluetooth = c.payloadVariant.bluetooth;
|
|
|
|
requiresReboot = true;
|
|
|
|
break;
|
2022-05-02 12:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
service.reloadConfig();
|
2022-08-22 21:41:23 +00:00
|
|
|
// Reboot 5 seconds after a config that requires rebooting is set
|
|
|
|
if (requiresReboot) {
|
|
|
|
DEBUG_MSG("Rebooting due to config changes\n");
|
|
|
|
screen->startRebootScreen();
|
|
|
|
rebootAtMsec = millis() + (5 * 1000);
|
|
|
|
}
|
2022-05-02 12:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdminModule::handleSetModuleConfig(const ModuleConfig &c)
|
|
|
|
{
|
|
|
|
switch (c.which_payloadVariant) {
|
2022-08-16 02:06:55 +00:00
|
|
|
case ModuleConfig_mqtt_tag:
|
|
|
|
DEBUG_MSG("Setting module config: MQTT\n");
|
|
|
|
moduleConfig.has_mqtt = true;
|
|
|
|
moduleConfig.mqtt = c.payloadVariant.mqtt;
|
|
|
|
break;
|
|
|
|
case ModuleConfig_serial_tag:
|
|
|
|
DEBUG_MSG("Setting module config: Serial\n");
|
|
|
|
moduleConfig.has_serial = true;
|
|
|
|
moduleConfig.serial = c.payloadVariant.serial;
|
|
|
|
break;
|
|
|
|
case ModuleConfig_external_notification_tag:
|
|
|
|
DEBUG_MSG("Setting module config: External Notification\n");
|
|
|
|
moduleConfig.has_external_notification = true;
|
|
|
|
moduleConfig.external_notification = c.payloadVariant.external_notification;
|
|
|
|
break;
|
|
|
|
case ModuleConfig_store_forward_tag:
|
|
|
|
DEBUG_MSG("Setting module config: Store & Forward\n");
|
|
|
|
moduleConfig.has_store_forward = true;
|
|
|
|
moduleConfig.store_forward = c.payloadVariant.store_forward;
|
|
|
|
break;
|
|
|
|
case ModuleConfig_range_test_tag:
|
|
|
|
DEBUG_MSG("Setting module config: Range Test\n");
|
|
|
|
moduleConfig.has_range_test = true;
|
|
|
|
moduleConfig.range_test = c.payloadVariant.range_test;
|
|
|
|
break;
|
|
|
|
case ModuleConfig_telemetry_tag:
|
|
|
|
DEBUG_MSG("Setting module config: Telemetry\n");
|
|
|
|
moduleConfig.has_telemetry = true;
|
|
|
|
moduleConfig.telemetry = c.payloadVariant.telemetry;
|
|
|
|
break;
|
|
|
|
case ModuleConfig_canned_message_tag:
|
|
|
|
DEBUG_MSG("Setting module config: Canned Message\n");
|
|
|
|
moduleConfig.has_canned_message = true;
|
|
|
|
moduleConfig.canned_message = c.payloadVariant.canned_message;
|
|
|
|
break;
|
2022-05-01 22:53:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
service.reloadConfig();
|
|
|
|
}
|
|
|
|
|
2022-05-02 12:00:24 +00:00
|
|
|
void AdminModule::handleSetChannel(const Channel &cc)
|
|
|
|
{
|
|
|
|
channels.setChannel(cc);
|
2022-05-07 03:34:06 +00:00
|
|
|
channels.onConfigChanged(); // tell the radios about this change
|
|
|
|
nodeDB.saveChannelsToDisk();
|
2022-05-02 12:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-03 12:16:50 +00:00
|
|
|
* Getters
|
2022-05-02 12:00:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
void AdminModule::handleGetOwner(const MeshPacket &req)
|
|
|
|
{
|
|
|
|
if (req.decoded.want_response) {
|
|
|
|
// We create the reply here
|
2022-05-03 12:16:50 +00:00
|
|
|
AdminMessage res = AdminMessage_init_default;
|
|
|
|
res.get_owner_response = owner;
|
2022-05-02 12:00:24 +00:00
|
|
|
|
2022-05-03 12:16:50 +00:00
|
|
|
res.which_variant = AdminMessage_get_owner_response_tag;
|
|
|
|
myReply = allocDataProtobuf(res);
|
2022-05-02 12:00:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-03 12:16:50 +00:00
|
|
|
void AdminModule::handleGetConfig(const MeshPacket &req, const uint32_t configType)
|
2022-05-02 12:00:24 +00:00
|
|
|
{
|
2022-05-03 12:16:50 +00:00
|
|
|
AdminMessage res = AdminMessage_init_default;
|
2022-05-02 12:00:24 +00:00
|
|
|
|
|
|
|
if (req.decoded.want_response) {
|
2022-05-03 12:16:50 +00:00
|
|
|
switch (configType) {
|
2022-05-02 12:00:24 +00:00
|
|
|
case AdminMessage_ConfigType_DEVICE_CONFIG:
|
|
|
|
DEBUG_MSG("Getting config: Device\n");
|
2022-05-07 10:31:21 +00:00
|
|
|
res.get_config_response.which_payloadVariant = Config_device_tag;
|
2022-05-21 20:38:33 +00:00
|
|
|
res.get_config_response.payloadVariant.device = config.device;
|
2022-05-02 12:00:24 +00:00
|
|
|
break;
|
2022-05-07 10:31:21 +00:00
|
|
|
case AdminMessage_ConfigType_POSITION_CONFIG:
|
|
|
|
DEBUG_MSG("Getting config: Position\n");
|
|
|
|
res.get_config_response.which_payloadVariant = Config_position_tag;
|
2022-05-21 20:38:33 +00:00
|
|
|
res.get_config_response.payloadVariant.position = config.position;
|
2022-05-02 12:00:24 +00:00
|
|
|
break;
|
|
|
|
case AdminMessage_ConfigType_POWER_CONFIG:
|
|
|
|
DEBUG_MSG("Getting config: Power\n");
|
2022-05-07 10:31:21 +00:00
|
|
|
res.get_config_response.which_payloadVariant = Config_power_tag;
|
2022-05-21 20:38:33 +00:00
|
|
|
res.get_config_response.payloadVariant.power = config.power;
|
2022-05-02 12:00:24 +00:00
|
|
|
break;
|
|
|
|
case AdminMessage_ConfigType_WIFI_CONFIG:
|
|
|
|
DEBUG_MSG("Getting config: WiFi\n");
|
2022-05-07 10:31:21 +00:00
|
|
|
res.get_config_response.which_payloadVariant = Config_wifi_tag;
|
2022-05-21 20:38:33 +00:00
|
|
|
res.get_config_response.payloadVariant.wifi = config.wifi;
|
|
|
|
writeSecret(res.get_config_response.payloadVariant.wifi.psk, config.wifi.psk);
|
2022-05-02 12:00:24 +00:00
|
|
|
break;
|
|
|
|
case AdminMessage_ConfigType_DISPLAY_CONFIG:
|
|
|
|
DEBUG_MSG("Getting config: Display\n");
|
2022-05-07 10:31:21 +00:00
|
|
|
res.get_config_response.which_payloadVariant = Config_display_tag;
|
2022-05-21 20:38:33 +00:00
|
|
|
res.get_config_response.payloadVariant.display = config.display;
|
2022-05-02 12:00:24 +00:00
|
|
|
break;
|
|
|
|
case AdminMessage_ConfigType_LORA_CONFIG:
|
|
|
|
DEBUG_MSG("Getting config: LoRa\n");
|
2022-05-07 10:31:21 +00:00
|
|
|
res.get_config_response.which_payloadVariant = Config_lora_tag;
|
2022-05-21 20:38:33 +00:00
|
|
|
res.get_config_response.payloadVariant.lora = config.lora;
|
2022-05-02 12:00:24 +00:00
|
|
|
break;
|
2022-08-16 02:06:55 +00:00
|
|
|
case AdminMessage_ConfigType_BLUETOOTH_CONFIG:
|
|
|
|
DEBUG_MSG("Getting config: Bluetooth\n");
|
|
|
|
res.get_config_response.which_payloadVariant = Config_bluetooth_tag;
|
|
|
|
res.get_config_response.payloadVariant.bluetooth = config.bluetooth;
|
|
|
|
break;
|
2022-05-02 12:00:24 +00:00
|
|
|
}
|
2022-06-12 14:44:23 +00:00
|
|
|
// NOTE: The phone app needs to know the ls_secs value so it can properly expect sleep behavior.
|
2022-05-02 12:00:24 +00:00
|
|
|
// So even if we internally use 0 to represent 'use default' we still need to send the value we are
|
|
|
|
// using to the app (so that even old phone apps work with new device loads).
|
|
|
|
// r.get_radio_response.preferences.ls_secs = getPref_ls_secs();
|
|
|
|
// hideSecret(r.get_radio_response.preferences.wifi_ssid); // hmm - leave public for now, because only minimally private
|
|
|
|
// and useful for users to know current provisioning) hideSecret(r.get_radio_response.preferences.wifi_password);
|
2022-05-07 10:31:21 +00:00
|
|
|
// r.get_config_response.which_payloadVariant = Config_ModuleConfig_telemetry_tag;
|
2022-05-03 12:16:50 +00:00
|
|
|
res.which_variant = AdminMessage_get_config_response_tag;
|
|
|
|
myReply = allocDataProtobuf(res);
|
2022-05-02 12:00:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-03 12:16:50 +00:00
|
|
|
void AdminModule::handleGetModuleConfig(const MeshPacket &req, const uint32_t configType)
|
2022-05-02 12:00:24 +00:00
|
|
|
{
|
2022-05-03 12:16:50 +00:00
|
|
|
AdminMessage res = AdminMessage_init_default;
|
2022-05-02 12:00:24 +00:00
|
|
|
|
|
|
|
if (req.decoded.want_response) {
|
2022-05-03 12:16:50 +00:00
|
|
|
switch (configType) {
|
2022-05-02 12:00:24 +00:00
|
|
|
case AdminMessage_ModuleConfigType_MQTT_CONFIG:
|
|
|
|
DEBUG_MSG("Getting module config: MQTT\n");
|
2022-05-07 10:31:21 +00:00
|
|
|
res.get_module_config_response.which_payloadVariant = ModuleConfig_mqtt_tag;
|
2022-05-22 11:27:56 +00:00
|
|
|
res.get_module_config_response.payloadVariant.mqtt = moduleConfig.mqtt;
|
2022-05-02 12:00:24 +00:00
|
|
|
break;
|
|
|
|
case AdminMessage_ModuleConfigType_SERIAL_CONFIG:
|
|
|
|
DEBUG_MSG("Getting module config: Serial\n");
|
2022-05-07 10:31:21 +00:00
|
|
|
res.get_module_config_response.which_payloadVariant = ModuleConfig_serial_tag;
|
2022-05-22 11:27:56 +00:00
|
|
|
res.get_module_config_response.payloadVariant.serial = moduleConfig.serial;
|
2022-05-02 12:00:24 +00:00
|
|
|
break;
|
|
|
|
case AdminMessage_ModuleConfigType_EXTNOTIF_CONFIG:
|
|
|
|
DEBUG_MSG("Getting module config: External Notification\n");
|
2022-05-07 10:31:21 +00:00
|
|
|
res.get_module_config_response.which_payloadVariant = ModuleConfig_external_notification_tag;
|
|
|
|
res.get_module_config_response.payloadVariant.external_notification =
|
2022-05-22 11:27:56 +00:00
|
|
|
moduleConfig.external_notification;
|
2022-05-02 12:00:24 +00:00
|
|
|
break;
|
|
|
|
case AdminMessage_ModuleConfigType_STOREFORWARD_CONFIG:
|
|
|
|
DEBUG_MSG("Getting module config: Store & Forward\n");
|
2022-05-07 10:31:21 +00:00
|
|
|
res.get_module_config_response.which_payloadVariant = ModuleConfig_store_forward_tag;
|
2022-05-22 11:27:56 +00:00
|
|
|
res.get_module_config_response.payloadVariant.store_forward = moduleConfig.store_forward;
|
2022-05-02 12:00:24 +00:00
|
|
|
break;
|
|
|
|
case AdminMessage_ModuleConfigType_RANGETEST_CONFIG:
|
|
|
|
DEBUG_MSG("Getting module config: Range Test\n");
|
2022-05-07 10:31:21 +00:00
|
|
|
res.get_module_config_response.which_payloadVariant = ModuleConfig_range_test_tag;
|
2022-05-22 11:27:56 +00:00
|
|
|
res.get_module_config_response.payloadVariant.range_test = moduleConfig.range_test;
|
2022-05-02 12:00:24 +00:00
|
|
|
break;
|
|
|
|
case AdminMessage_ModuleConfigType_TELEMETRY_CONFIG:
|
|
|
|
DEBUG_MSG("Getting module config: Telemetry\n");
|
2022-05-07 10:31:21 +00:00
|
|
|
res.get_module_config_response.which_payloadVariant = ModuleConfig_telemetry_tag;
|
2022-05-22 11:27:56 +00:00
|
|
|
res.get_module_config_response.payloadVariant.telemetry = moduleConfig.telemetry;
|
2022-05-02 12:00:24 +00:00
|
|
|
break;
|
|
|
|
case AdminMessage_ModuleConfigType_CANNEDMSG_CONFIG:
|
|
|
|
DEBUG_MSG("Getting module config: Canned Message\n");
|
2022-05-07 10:31:21 +00:00
|
|
|
res.get_module_config_response.which_payloadVariant = ModuleConfig_canned_message_tag;
|
2022-05-22 11:27:56 +00:00
|
|
|
res.get_module_config_response.payloadVariant.canned_message = moduleConfig.canned_message;
|
2022-05-02 12:00:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-06-12 14:44:23 +00:00
|
|
|
// NOTE: The phone app needs to know the ls_secsvalue so it can properly expect sleep behavior.
|
2022-05-02 12:00:24 +00:00
|
|
|
// So even if we internally use 0 to represent 'use default' we still need to send the value we are
|
|
|
|
// using to the app (so that even old phone apps work with new device loads).
|
|
|
|
// r.get_radio_response.preferences.ls_secs = getPref_ls_secs();
|
|
|
|
// hideSecret(r.get_radio_response.preferences.wifi_ssid); // hmm - leave public for now, because only minimally private
|
|
|
|
// and useful for users to know current provisioning) hideSecret(r.get_radio_response.preferences.wifi_password);
|
2022-05-07 10:31:21 +00:00
|
|
|
// r.get_config_response.which_payloadVariant = Config_ModuleConfig_telemetry_tag;
|
2022-05-03 12:16:50 +00:00
|
|
|
res.which_variant = AdminMessage_get_module_config_response_tag;
|
|
|
|
myReply = allocDataProtobuf(res);
|
2022-05-02 12:00:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-08 12:19:04 +00:00
|
|
|
void AdminModule::handleGetDeviceMetadata(const MeshPacket &req) {
|
|
|
|
AdminMessage r = AdminMessage_init_default;
|
|
|
|
|
|
|
|
DeviceMetadata deviceMetadata;
|
|
|
|
strncpy(deviceMetadata.firmware_version, myNodeInfo.firmware_version, 18);
|
|
|
|
deviceMetadata.device_state_version = DEVICESTATE_CUR_VER;
|
|
|
|
|
|
|
|
r.get_device_metadata_response = deviceMetadata;
|
|
|
|
r.which_variant = AdminMessage_get_device_metadata_response_tag;
|
|
|
|
myReply = allocDataProtobuf(r);
|
|
|
|
}
|
|
|
|
|
2022-05-02 12:00:24 +00:00
|
|
|
void AdminModule::handleGetChannel(const MeshPacket &req, uint32_t channelIndex)
|
|
|
|
{
|
|
|
|
if (req.decoded.want_response) {
|
|
|
|
// We create the reply here
|
|
|
|
AdminMessage r = AdminMessage_init_default;
|
|
|
|
r.get_channel_response = channels.getByIndex(channelIndex);
|
|
|
|
r.which_variant = AdminMessage_get_channel_response_tag;
|
|
|
|
myReply = allocDataProtobuf(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-09 08:01:43 +00:00
|
|
|
AdminModule::AdminModule() : ProtobufModule("Admin", PortNum_ADMIN_APP, AdminMessage_fields)
|
2021-02-26 07:34:00 +00:00
|
|
|
{
|
2021-03-11 02:01:57 +00:00
|
|
|
// restrict to the admin channel for rx
|
2021-03-13 05:14:27 +00:00
|
|
|
boundChannel = Channels::adminChannel;
|
2021-02-21 06:03:44 +00:00
|
|
|
}
|