Added Remove node by nodenum admin message (#2941)

* Remove node by nodenum

* It were backerds! DERP
This commit is contained in:
Ben Meadors 2023-11-16 06:57:22 -06:00 committed by GitHub
parent 91e399a2b6
commit 5d917885df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 7 deletions

@ -1 +1 @@
Subproject commit 59a67810ca07b731839cf1b44b142778fa55b5bf Subproject commit c845b7848eebb11150ca0427773303bf8758e533

View File

@ -323,6 +323,20 @@ void NodeDB::resetNodes()
neighborInfoModule->resetNeighbors(); neighborInfoModule->resetNeighbors();
} }
void NodeDB::removeNodeByNum(uint nodeNum)
{
int newPos = 0, removed = 0;
for (int i = 0; i < *numMeshNodes; i++) {
if (meshNodes[i].num != nodeNum)
meshNodes[newPos++] = meshNodes[i];
else
removed++;
}
*numMeshNodes -= removed;
LOG_DEBUG("NodeDB::removeNodeByNum purged %d entries. Saving changes...\n", removed);
saveDeviceStateToDisk();
}
void NodeDB::cleanupMeshDB() void NodeDB::cleanupMeshDB()
{ {
int newPos = 0, removed = 0; int newPos = 0, removed = 0;

View File

@ -111,7 +111,7 @@ class NodeDB
/// Return the number of nodes we've heard from recently (within the last 2 hrs?) /// Return the number of nodes we've heard from recently (within the last 2 hrs?)
size_t getNumOnlineMeshNodes(); size_t getNumOnlineMeshNodes();
void initConfigIntervals(), initModuleConfigIntervals(), resetNodes(); void initConfigIntervals(), initModuleConfigIntervals(), resetNodes(), removeNodeByNum(uint nodeNum);
bool factoryReset(); bool factoryReset();

View File

@ -145,6 +145,8 @@ typedef struct _meshtastic_AdminMessage {
char set_canned_message_module_messages[201]; char set_canned_message_module_messages[201];
/* Set the ringtone for ExternalNotification. */ /* Set the ringtone for ExternalNotification. */
char set_ringtone_message[231]; char set_ringtone_message[231];
/* Remove the node by the specified node-num from the NodeDB on the device */
uint32_t remove_by_nodenum;
/* Begins an edit transaction for config, module config, owner, and channel settings changes /* Begins an edit transaction for config, module config, owner, and channel settings changes
This will delay the standard *implicit* save to the file system and subsequent reboot behavior until committed (commit_edit_settings) */ This will delay the standard *implicit* save to the file system and subsequent reboot behavior until committed (commit_edit_settings) */
bool begin_edit_settings; bool begin_edit_settings;
@ -226,6 +228,7 @@ extern "C" {
#define meshtastic_AdminMessage_set_module_config_tag 35 #define meshtastic_AdminMessage_set_module_config_tag 35
#define meshtastic_AdminMessage_set_canned_message_module_messages_tag 36 #define meshtastic_AdminMessage_set_canned_message_module_messages_tag 36
#define meshtastic_AdminMessage_set_ringtone_message_tag 37 #define meshtastic_AdminMessage_set_ringtone_message_tag 37
#define meshtastic_AdminMessage_remove_by_nodenum_tag 38
#define meshtastic_AdminMessage_begin_edit_settings_tag 64 #define meshtastic_AdminMessage_begin_edit_settings_tag 64
#define meshtastic_AdminMessage_commit_edit_settings_tag 65 #define meshtastic_AdminMessage_commit_edit_settings_tag 65
#define meshtastic_AdminMessage_reboot_ota_seconds_tag 95 #define meshtastic_AdminMessage_reboot_ota_seconds_tag 95
@ -262,6 +265,7 @@ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_config,set_config), 34)
X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_module_config,set_module_config), 35) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_module_config,set_module_config), 35) \
X(a, STATIC, ONEOF, STRING, (payload_variant,set_canned_message_module_messages,set_canned_message_module_messages), 36) \ X(a, STATIC, ONEOF, STRING, (payload_variant,set_canned_message_module_messages,set_canned_message_module_messages), 36) \
X(a, STATIC, ONEOF, STRING, (payload_variant,set_ringtone_message,set_ringtone_message), 37) \ X(a, STATIC, ONEOF, STRING, (payload_variant,set_ringtone_message,set_ringtone_message), 37) \
X(a, STATIC, ONEOF, UINT32, (payload_variant,remove_by_nodenum,remove_by_nodenum), 38) \
X(a, STATIC, ONEOF, BOOL, (payload_variant,begin_edit_settings,begin_edit_settings), 64) \ X(a, STATIC, ONEOF, BOOL, (payload_variant,begin_edit_settings,begin_edit_settings), 64) \
X(a, STATIC, ONEOF, BOOL, (payload_variant,commit_edit_settings,commit_edit_settings), 65) \ X(a, STATIC, ONEOF, BOOL, (payload_variant,commit_edit_settings,commit_edit_settings), 65) \
X(a, STATIC, ONEOF, INT32, (payload_variant,reboot_ota_seconds,reboot_ota_seconds), 95) \ X(a, STATIC, ONEOF, INT32, (payload_variant,reboot_ota_seconds,reboot_ota_seconds), 95) \

View File

@ -343,7 +343,7 @@ typedef struct _meshtastic_Config_NetworkConfig {
acquire an address via DHCP */ acquire an address via DHCP */
char wifi_ssid[33]; char wifi_ssid[33];
/* If set, will be use to authenticate to the named wifi */ /* If set, will be use to authenticate to the named wifi */
char wifi_psk[64]; char wifi_psk[65];
/* NTP server to use if WiFi is conneced, defaults to `0.pool.ntp.org` */ /* NTP server to use if WiFi is conneced, defaults to `0.pool.ntp.org` */
char ntp_server[33]; char ntp_server[33];
/* Enable Ethernet */ /* Enable Ethernet */
@ -790,10 +790,10 @@ extern const pb_msgdesc_t meshtastic_Config_BluetoothConfig_msg;
#define meshtastic_Config_DisplayConfig_size 28 #define meshtastic_Config_DisplayConfig_size 28
#define meshtastic_Config_LoRaConfig_size 77 #define meshtastic_Config_LoRaConfig_size 77
#define meshtastic_Config_NetworkConfig_IpV4Config_size 20 #define meshtastic_Config_NetworkConfig_IpV4Config_size 20
#define meshtastic_Config_NetworkConfig_size 195 #define meshtastic_Config_NetworkConfig_size 196
#define meshtastic_Config_PositionConfig_size 60 #define meshtastic_Config_PositionConfig_size 60
#define meshtastic_Config_PowerConfig_size 40 #define meshtastic_Config_PowerConfig_size 40
#define meshtastic_Config_size 198 #define meshtastic_Config_size 199
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */

View File

@ -316,7 +316,7 @@ extern const pb_msgdesc_t meshtastic_NodeRemoteHardwarePin_msg;
#define meshtastic_DeviceState_size 16854 #define meshtastic_DeviceState_size 16854
#define meshtastic_NodeInfoLite_size 151 #define meshtastic_NodeInfoLite_size 151
#define meshtastic_NodeRemoteHardwarePin_size 29 #define meshtastic_NodeRemoteHardwarePin_size 29
#define meshtastic_OEMStore_size 3230 #define meshtastic_OEMStore_size 3231
#define meshtastic_PositionLite_size 28 #define meshtastic_PositionLite_size 28
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -174,7 +174,7 @@ extern const pb_msgdesc_t meshtastic_LocalModuleConfig_msg;
#define meshtastic_LocalModuleConfig_fields &meshtastic_LocalModuleConfig_msg #define meshtastic_LocalModuleConfig_fields &meshtastic_LocalModuleConfig_msg
/* Maximum encoded size of messages (where known) */ /* Maximum encoded size of messages (where known) */
#define meshtastic_LocalConfig_size 463 #define meshtastic_LocalConfig_size 464
#define meshtastic_LocalModuleConfig_size 621 #define meshtastic_LocalModuleConfig_size 621
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -182,6 +182,12 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta
} }
break; break;
} }
case meshtastic_AdminMessage_remove_by_nodenum_tag: {
LOG_INFO("Client is receiving a remove_nodenum command.\n");
nodeDB.removeNodeByNum(r->remove_by_nodenum);
reboot(DEFAULT_REBOOT_SECONDS);
break;
}
#ifdef ARCH_PORTDUINO #ifdef ARCH_PORTDUINO
case meshtastic_AdminMessage_exit_simulator_tag: case meshtastic_AdminMessage_exit_simulator_tag:
LOG_INFO("Exiting simulator\n"); LOG_INFO("Exiting simulator\n");