sforkowany z mirror/meshtastic-firmware
add handleSetConfig, remove team
rodzic
3a1f20821e
commit
8f038ced15
2
proto
2
proto
|
@ -1 +1 @@
|
|||
Subproject commit 8778b41906c4b1d0bd6053823f41cd4135160a8f
|
||||
Subproject commit cb7bf9ac239b87c6a988feb0bb49c8a3e85dea0e
|
|
@ -53,6 +53,7 @@ typedef struct _AdminMessage {
|
|||
AdminMessage_ConfigType get_config_request;
|
||||
Config get_config_response;
|
||||
Config set_config;
|
||||
bool confirm_set_config;
|
||||
bool confirm_set_channel;
|
||||
bool confirm_set_radio;
|
||||
bool exit_simulator;
|
||||
|
@ -101,6 +102,7 @@ extern "C" {
|
|||
#define AdminMessage_get_config_request_tag 10
|
||||
#define AdminMessage_get_config_response_tag 11
|
||||
#define AdminMessage_set_config_tag 12
|
||||
#define AdminMessage_confirm_set_config_tag 13
|
||||
#define AdminMessage_confirm_set_channel_tag 32
|
||||
#define AdminMessage_confirm_set_radio_tag 33
|
||||
#define AdminMessage_exit_simulator_tag 34
|
||||
|
@ -133,6 +135,7 @@ X(a, STATIC, ONEOF, MESSAGE, (variant,get_owner_response,get_owner_respons
|
|||
X(a, STATIC, ONEOF, UENUM, (variant,get_config_request,get_config_request), 10) \
|
||||
X(a, STATIC, ONEOF, MESSAGE, (variant,get_config_response,get_config_response), 11) \
|
||||
X(a, STATIC, ONEOF, MESSAGE, (variant,set_config,set_config), 12) \
|
||||
X(a, STATIC, ONEOF, BOOL, (variant,confirm_set_config,confirm_set_config), 13) \
|
||||
X(a, STATIC, ONEOF, BOOL, (variant,confirm_set_channel,confirm_set_channel), 32) \
|
||||
X(a, STATIC, ONEOF, BOOL, (variant,confirm_set_radio,confirm_set_radio), 33) \
|
||||
X(a, STATIC, ONEOF, BOOL, (variant,exit_simulator,exit_simulator), 34) \
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include "configuration.h"
|
||||
#include "AdminModule.h"
|
||||
#include "Channels.h"
|
||||
#include "MeshService.h"
|
||||
#include "NodeDB.h"
|
||||
#include "Router.h"
|
||||
#include "configuration.h"
|
||||
#include "main.h"
|
||||
|
||||
#ifdef PORTDUINO
|
||||
|
@ -13,18 +13,21 @@
|
|||
AdminModule *adminModule;
|
||||
|
||||
/// A special reserved string to indicate strings we can not share with external nodes. We will use this 'reserved' word instead.
|
||||
/// 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.
|
||||
/// 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.
|
||||
static const char *secretReserved = "sekrit";
|
||||
|
||||
/// If buf is !empty, change it to secret
|
||||
static void hideSecret(char *buf) {
|
||||
static void hideSecret(char *buf)
|
||||
{
|
||||
if (*buf) {
|
||||
strcpy(buf, secretReserved);
|
||||
}
|
||||
}
|
||||
|
||||
/// If buf is the reserved secret word, replace the buffer with currentVal
|
||||
static void writeSecret(char *buf, const char *currentVal) {
|
||||
static void writeSecret(char *buf, const char *currentVal)
|
||||
{
|
||||
if (strcmp(buf, secretReserved) == 0) {
|
||||
strcpy(buf, currentVal);
|
||||
}
|
||||
|
@ -53,7 +56,8 @@ void AdminModule::handleGetRadio(const MeshPacket &req)
|
|||
// 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();
|
||||
r.get_radio_response.preferences.phone_timeout_secs = getPref_phone_timeout_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_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);
|
||||
|
||||
r.which_variant = AdminMessage_get_radio_response_tag;
|
||||
|
@ -69,70 +73,70 @@ void AdminModule::handleGetConfig(const MeshPacket &req)
|
|||
if (req.decoded.want_response) {
|
||||
switch (r.get_config_request) {
|
||||
case AdminMessage_ConfigType_ALL:
|
||||
DEBUG_MSG("Requesting AdminMessage_ConfigType_ALL\n");
|
||||
DEBUG_MSG("Requesting config: AdminMessage_ConfigType_ALL\n");
|
||||
r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_ALL;
|
||||
break;
|
||||
case AdminMessage_ConfigType_CORE_ONLY:
|
||||
DEBUG_MSG("Requesting AdminMessage_ConfigType_CORE_ONLY\n");
|
||||
DEBUG_MSG("Requesting config: AdminMessage_ConfigType_CORE_ONLY\n");
|
||||
r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_CORE_ONLY;
|
||||
break;
|
||||
case AdminMessage_ConfigType_MODULE_ONLY:
|
||||
DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_ONLY\n");
|
||||
DEBUG_MSG("Requesting config: AdminMessage_ConfigType_MODULE_ONLY\n");
|
||||
r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_ONLY;
|
||||
break;
|
||||
case AdminMessage_ConfigType_DEVICE_CONFIG:
|
||||
DEBUG_MSG("Requesting AdminMessage_ConfigType_DEVICE_CONFIG\n");
|
||||
DEBUG_MSG("Requesting config: AdminMessage_ConfigType_DEVICE_CONFIG\n");
|
||||
r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_DEVICE_CONFIG;
|
||||
break;
|
||||
case AdminMessage_ConfigType_GPS_CONFIG:
|
||||
DEBUG_MSG("Requesting AdminMessage_ConfigType_GPS_CONFIG\n");
|
||||
DEBUG_MSG("Requesting config: AdminMessage_ConfigType_GPS_CONFIG\n");
|
||||
r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_GPS_CONFIG;
|
||||
break;
|
||||
case AdminMessage_ConfigType_POWER_CONFIG:
|
||||
DEBUG_MSG("Requesting AdminMessage_ConfigType_POWER_CONFIG\n");
|
||||
DEBUG_MSG("Requesting config: AdminMessage_ConfigType_POWER_CONFIG\n");
|
||||
r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_POWER_CONFIG;
|
||||
break;
|
||||
case AdminMessage_ConfigType_WIFI_CONFIG:
|
||||
DEBUG_MSG("Requesting AdminMessage_ConfigType_WIFI_CONFIG\n");
|
||||
DEBUG_MSG("Requesting config: AdminMessage_ConfigType_WIFI_CONFIG\n");
|
||||
r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_POWER_CONFIG;
|
||||
break;
|
||||
case AdminMessage_ConfigType_DISPLAY_CONFIG:
|
||||
DEBUG_MSG("Requesting AdminMessage_ConfigType_DISPLAY_CONFIG\n");
|
||||
DEBUG_MSG("Requesting config: AdminMessage_ConfigType_DISPLAY_CONFIG\n");
|
||||
r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_DISPLAY_CONFIG;
|
||||
break;
|
||||
case AdminMessage_ConfigType_LORA_CONFIG:
|
||||
DEBUG_MSG("Requesting AdminMessage_ConfigType_LORA_CONFIG\n");
|
||||
DEBUG_MSG("Requesting config: AdminMessage_ConfigType_LORA_CONFIG\n");
|
||||
r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_LORA_CONFIG;
|
||||
break;
|
||||
case AdminMessage_ConfigType_MODULE_MQTT_CONFIG:
|
||||
DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_MQTT_CONFIG\n");
|
||||
DEBUG_MSG("Requesting config: AdminMessage_ConfigType_MODULE_MQTT_CONFIG\n");
|
||||
r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_MQTT_CONFIG;
|
||||
break;
|
||||
case AdminMessage_ConfigType_MODULE_SERIAL_CONFIG:
|
||||
DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_SERIAL_CONFIG\n");
|
||||
DEBUG_MSG("Requesting config: AdminMessage_ConfigType_MODULE_SERIAL_CONFIG\n");
|
||||
r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_SERIAL_CONFIG;
|
||||
break;
|
||||
case AdminMessage_ConfigType_MODULE_EXTNOTIF_CONFIG:
|
||||
DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_EXTNOTIF_CONFIG\n");
|
||||
DEBUG_MSG("Requesting config: AdminMessage_ConfigType_MODULE_EXTNOTIF_CONFIG\n");
|
||||
r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_EXTNOTIF_CONFIG;
|
||||
break;
|
||||
case AdminMessage_ConfigType_MODULE_STOREFORWARD_CONFIG:
|
||||
DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_STOREFORWARD_CONFIG\n");
|
||||
DEBUG_MSG("Requesting config: AdminMessage_ConfigType_MODULE_STOREFORWARD_CONFIG\n");
|
||||
r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_STOREFORWARD_CONFIG;
|
||||
break;
|
||||
case AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG:
|
||||
DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG\n");
|
||||
DEBUG_MSG("Requesting config: AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG\n");
|
||||
r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG;
|
||||
break;
|
||||
case AdminMessage_ConfigType_MODULE_TELEMETRY_CONFIG:
|
||||
DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_TELEMETRY_CONFIG\n");
|
||||
DEBUG_MSG("Requesting config: AdminMessage_ConfigType_MODULE_TELEMETRY_CONFIG\n");
|
||||
r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_TELEMETRY_CONFIG;
|
||||
r.get_config_response.payloadVariant.module_config.which_payloadVariant = Config_ModuleConfig_telemetry_config_tag;
|
||||
r.get_config_response.payloadVariant.module_config.payloadVariant.telemetry_config =
|
||||
config.payloadVariant.module_config.payloadVariant.telemetry_config;
|
||||
break;
|
||||
case AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG:
|
||||
DEBUG_MSG("Requesting AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG\n");
|
||||
DEBUG_MSG("Requesting config: AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG\n");
|
||||
r.get_config_response.which_payloadVariant = AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG;
|
||||
break;
|
||||
default:
|
||||
|
@ -144,8 +148,8 @@ void AdminModule::handleGetConfig(const MeshPacket &req)
|
|||
// 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();
|
||||
// r.get_radio_response.preferences.phone_timeout_secs = getPref_phone_timeout_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);
|
||||
// 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);
|
||||
|
||||
r.which_variant = AdminMessage_get_config_response_tag;
|
||||
myReply = allocDataProtobuf(r);
|
||||
|
@ -209,6 +213,11 @@ bool AdminModule::handleReceivedProtobuf(const MeshPacket &mp, AdminMessage *r)
|
|||
handleGetConfig(mp);
|
||||
break;
|
||||
|
||||
case AdminMessage_set_config_tag:
|
||||
DEBUG_MSG("Client is setting the config\n");
|
||||
handleSetConfig(r->set_config);
|
||||
break;
|
||||
|
||||
case AdminMessage_get_owner_request_tag:
|
||||
DEBUG_MSG("Client is getting owner\n");
|
||||
handleGetOwner(mp);
|
||||
|
@ -238,16 +247,11 @@ bool AdminModule::handleReceivedProtobuf(const MeshPacket &mp, AdminMessage *r)
|
|||
AdminMessage response = AdminMessage_init_default;
|
||||
AdminMessageHandleResult handleResult = MeshModule::handleAdminMessageForAllPlugins(mp, r, &response);
|
||||
|
||||
if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE)
|
||||
{
|
||||
if (handleResult == AdminMessageHandleResult::HANDLED_WITH_RESPONSE) {
|
||||
myReply = allocDataProtobuf(response);
|
||||
}
|
||||
else if (mp.decoded.want_response)
|
||||
{
|
||||
} else if (mp.decoded.want_response) {
|
||||
DEBUG_MSG("We did not responded to a request that wanted a respond. req.variant=%d\n", r->which_variant);
|
||||
}
|
||||
else if (handleResult != AdminMessageHandleResult::HANDLED)
|
||||
{
|
||||
} else if (handleResult != AdminMessageHandleResult::HANDLED) {
|
||||
// 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);
|
||||
}
|
||||
|
@ -303,6 +307,66 @@ void AdminModule::handleSetRadio(RadioConfig &r)
|
|||
service.reloadConfig();
|
||||
}
|
||||
|
||||
void AdminModule::handleSetConfig(Config &c)
|
||||
{
|
||||
switch (c.which_payloadVariant) {
|
||||
case AdminMessage_ConfigType_ALL:
|
||||
DEBUG_MSG("Setting config: AdminMessage_ConfigType_ALL\n");
|
||||
break;
|
||||
case AdminMessage_ConfigType_CORE_ONLY:
|
||||
DEBUG_MSG("Setting config: AdminMessage_ConfigType_CORE_ONLY\n");
|
||||
break;
|
||||
case AdminMessage_ConfigType_MODULE_ONLY:
|
||||
DEBUG_MSG("Setting config: AdminMessage_ConfigType_MODULE_ONLY\n");
|
||||
break;
|
||||
case AdminMessage_ConfigType_DEVICE_CONFIG:
|
||||
DEBUG_MSG("Setting config: AdminMessage_ConfigType_DEVICE_CONFIG\n");
|
||||
break;
|
||||
case AdminMessage_ConfigType_GPS_CONFIG:
|
||||
DEBUG_MSG("Setting config: AdminMessage_ConfigType_GPS_CONFIG\n");
|
||||
break;
|
||||
case AdminMessage_ConfigType_POWER_CONFIG:
|
||||
DEBUG_MSG("Setting config: AdminMessage_ConfigType_POWER_CONFIG\n");
|
||||
break;
|
||||
case AdminMessage_ConfigType_WIFI_CONFIG:
|
||||
DEBUG_MSG("Setting config: AdminMessage_ConfigType_WIFI_CONFIG\n");
|
||||
break;
|
||||
case AdminMessage_ConfigType_DISPLAY_CONFIG:
|
||||
DEBUG_MSG("Setting config: AdminMessage_ConfigType_DISPLAY_CONFIG\n");
|
||||
break;
|
||||
case AdminMessage_ConfigType_LORA_CONFIG:
|
||||
DEBUG_MSG("Setting config: AdminMessage_ConfigType_LORA_CONFIG\n");
|
||||
break;
|
||||
case AdminMessage_ConfigType_MODULE_MQTT_CONFIG:
|
||||
DEBUG_MSG("Setting config: AdminMessage_ConfigType_MODULE_MQTT_CONFIG\n");
|
||||
break;
|
||||
case AdminMessage_ConfigType_MODULE_SERIAL_CONFIG:
|
||||
DEBUG_MSG("Setting config: AdminMessage_ConfigType_MODULE_SERIAL_CONFIG\n");
|
||||
break;
|
||||
case AdminMessage_ConfigType_MODULE_EXTNOTIF_CONFIG:
|
||||
DEBUG_MSG("Setting config: AdminMessage_ConfigType_MODULE_EXTNOTIF_CONFIG\n");
|
||||
break;
|
||||
case AdminMessage_ConfigType_MODULE_STOREFORWARD_CONFIG:
|
||||
DEBUG_MSG("Setting config: AdminMessage_ConfigType_MODULE_STOREFORWARD_CONFIG\n");
|
||||
break;
|
||||
case AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG:
|
||||
DEBUG_MSG("Setting config: AdminMessage_ConfigType_MODULE_RANGETEST_CONFIG\n");
|
||||
break;
|
||||
case AdminMessage_ConfigType_MODULE_TELEMETRY_CONFIG:
|
||||
DEBUG_MSG("Setting config: AdminMessage_ConfigType_MODULE_TELEMETRY_CONFIG\n");
|
||||
config.payloadVariant.module_config.payloadVariant.telemetry_config =
|
||||
c.payloadVariant.module_config.payloadVariant.telemetry_config;
|
||||
break;
|
||||
case AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG:
|
||||
DEBUG_MSG("Setting config: AdminMessage_ConfigType_MODULE_CANNEDMSG_CONFIG\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
service.reloadConfig();
|
||||
}
|
||||
|
||||
AdminModule::AdminModule() : ProtobufModule("Admin", PortNum_ADMIN_APP, AdminMessage_fields)
|
||||
{
|
||||
// restrict to the admin channel for rx
|
||||
|
|
|
@ -23,6 +23,7 @@ class AdminModule : public ProtobufModule<AdminMessage>
|
|||
void handleSetOwner(const User &o);
|
||||
void handleSetChannel(const Channel &cc);
|
||||
void handleSetRadio(RadioConfig &r);
|
||||
void handleSetConfig(Config &c);
|
||||
|
||||
void handleGetChannel(const MeshPacket &req, uint32_t channelIndex);
|
||||
void handleGetRadio(const MeshPacket &req);
|
||||
|
|
Ładowanie…
Reference in New Issue