switched to channel hash for durability

This commit is contained in:
medentem 2024-12-15 18:46:31 -06:00
parent 617297549f
commit 89a3d3ec10
4 changed files with 17 additions and 6 deletions

View File

@ -314,6 +314,15 @@ void Channels::setChannel(const meshtastic_Channel &c)
old = c; // slam in the new settings/role
}
int8_t Channels::getIndexByHash(ChannelHash channelHash)
{
for (int i = 0; i < getNumChannels(); i++)
if (getHash(i) == channelHash)
return i;
return -1;
}
bool Channels::anyMqttEnabled()
{
#if USERPREFS_EVENT_MODE

View File

@ -92,6 +92,9 @@ class Channels
// Returns true if any of our channels have enabled MQTT uplink or downlink
bool anyMqttEnabled();
/** Return the channel index for the specified channel hash, or -1 for not found */
int8_t getIndexByHash(ChannelHash channelHash);
private:
/** Given a channel index, change to use the crypto key specified by that index
*
@ -99,9 +102,6 @@ class Channels
*/
int16_t setCrypto(ChannelIndex chIndex);
/** Return the channel index for the specified channel hash, or -1 for not found */
int8_t getIndexByHash(ChannelHash channelHash);
/** Given a channel number, return the (0 to 255) hash for that channel
* If no suitable channel could be found, return -1
*

View File

@ -1,6 +1,7 @@
#include "NodeInfoModule.h"
#include "Default.h"
#include "MeshService.h"
#include "Channels.h"
#include "NodeDB.h"
#include "RTC.h"
#include "Router.h"
@ -53,10 +54,11 @@ void NodeInfoModule::sendOurNodeInfo(NodeNum dest, bool wantReplies, uint8_t cha
LOG_DEBUG("Send ourNodeInfo to channel %d", channel);
p->channel = channel;
}
#ifdef USERPREFS_CONFIG_DISCOVERY_CHANNEL
#ifdef USERPREFS_CONFIG_DISCOVERY_CHANNEL_HASH
// If this is a broadcast over the default channel, we can safely change this to the discovery channel if defined
if (dest == NODENUM_BROADCAST && channel == 0) {
p->channel = USERPREFS_CONFIG_DISCOVERY_CHANNEL;
int8_t discoveryChannelIdx = channels.getIndexByHash((ChannelHash)USERPREFS_CONFIG_DISCOVERY_CHANNEL_HASH);
p->channel = discoveryChannelIdx > 0 ? discoveryChannelIdx : 0;
}
#endif

View File

@ -317,7 +317,7 @@ void PositionModule::sendOurPosition()
LOG_INFO("Send pos@%x:6 to mesh (wantReplies=%d)", localPosition.timestamp, requestReplies);
sendOurPosition(NODENUM_BROADCAST, requestReplies);
#ifdef USERPREFS_CONFIG_DISCOVERY_CHANNEL
#ifdef USERPREFS_CONFIG_DISCOVERY_CHANNEL_HASH
// If the user wants discovery on a different channel, send only nodeinfo to that channel
// sendOurNodeInfo() will automatically handle routing a nodeinfo packet to the correct channel
assert(nodeInfoModule);