mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-09 06:32:06 +00:00
Add nodedb channel handling (#2384)
* send ourNodeInfo to channel we got a message we heared someone new * store node-channel into nodeDB * use channel from nodeDb to send local messages * update protobufs * fmt and fix braces * respect requested channel for local send, only store channel while getting a nodeinfo packet --------- Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com> Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
parent
82ba59765c
commit
26d18244f0
@ -77,8 +77,8 @@ int MeshService::handleFromRadio(const meshtastic_MeshPacket *mp)
|
||||
|
||||
nodeDB.updateFrom(*mp); // update our DB state based off sniffing every RX packet from the radio
|
||||
if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag && !nodeDB.getNode(mp->from)->has_user && nodeInfoModule) {
|
||||
LOG_INFO("Heard a node we don't know, sending NodeInfo and asking for a response.\n");
|
||||
nodeInfoModule->sendOurNodeInfo(mp->from, true);
|
||||
LOG_INFO("Heard a node on channel %d we don't know, sending NodeInfo and asking for a response.\n", mp->channel);
|
||||
nodeInfoModule->sendOurNodeInfo(mp->from, true, mp->channel);
|
||||
}
|
||||
|
||||
printPacket("Forwarding to phone", mp);
|
||||
@ -242,13 +242,13 @@ void MeshService::sendNetworkPing(NodeNum dest, bool wantReplies)
|
||||
|
||||
if (node->has_position && (node->position.latitude_i != 0 || node->position.longitude_i != 0)) {
|
||||
if (positionModule) {
|
||||
LOG_INFO("Sending position ping to 0x%x, wantReplies=%d\n", dest, wantReplies);
|
||||
positionModule->sendOurPosition(dest, wantReplies);
|
||||
LOG_INFO("Sending position ping to 0x%x, wantReplies=%d, channel=%d\n", dest, wantReplies, node->channel);
|
||||
positionModule->sendOurPosition(dest, wantReplies, node->channel);
|
||||
}
|
||||
} else {
|
||||
if (nodeInfoModule) {
|
||||
LOG_INFO("Sending nodeinfo ping to 0x%x, wantReplies=%d\n", dest, wantReplies);
|
||||
nodeInfoModule->sendOurNodeInfo(dest, wantReplies);
|
||||
LOG_INFO("Sending nodeinfo ping to 0x%x, wantReplies=%d, channel=%d\n", dest, wantReplies, node->channel);
|
||||
nodeInfoModule->sendOurNodeInfo(dest, wantReplies, node->channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -721,7 +721,7 @@ void NodeDB::updateUser(uint32_t nodeId, const meshtastic_User &p)
|
||||
void NodeDB::updateFrom(const meshtastic_MeshPacket &mp)
|
||||
{
|
||||
if (mp.which_payload_variant == meshtastic_MeshPacket_decoded_tag && mp.from) {
|
||||
LOG_DEBUG("Update DB node 0x%x, rx_time=%u\n", mp.from, mp.rx_time);
|
||||
LOG_DEBUG("Update DB node 0x%x, rx_time=%u, channel=%d\n", mp.from, mp.rx_time, mp.channel);
|
||||
|
||||
meshtastic_NodeInfo *info = getOrCreateNode(getFrom(&mp));
|
||||
if (!info) {
|
||||
@ -733,7 +733,20 @@ void NodeDB::updateFrom(const meshtastic_MeshPacket &mp)
|
||||
|
||||
if (mp.rx_snr)
|
||||
info->snr = mp.rx_snr; // keep the most recent SNR we received for this node.
|
||||
|
||||
if (mp.decoded.portnum == meshtastic_PortNum_NODEINFO_APP) {
|
||||
info->channel = mp.channel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t NodeDB::getNodeChannel(NodeNum n)
|
||||
{
|
||||
meshtastic_NodeInfo *info = getNode(n);
|
||||
if (!info) {
|
||||
return 0; // defaults to PRIMARY
|
||||
}
|
||||
return info->channel;
|
||||
}
|
||||
|
||||
/// Find a node in our DB, return null for missing
|
||||
|
@ -113,6 +113,9 @@ class NodeDB
|
||||
/// pick a provisional nodenum we hope no one is using
|
||||
void pickNewNodeNum();
|
||||
|
||||
// get channel channel index we heard a nodeNum on, defaults to 0 if not found
|
||||
uint8_t getNodeChannel(NodeNum n);
|
||||
|
||||
/// Find a node in our DB, return null for missing
|
||||
meshtastic_NodeInfo *getNode(NodeNum n);
|
||||
|
||||
|
@ -173,6 +173,10 @@ ErrorCode Router::sendLocal(meshtastic_MeshPacket *p, RxSource src)
|
||||
handleReceived(p, src);
|
||||
}
|
||||
|
||||
if (p->channel) // don't override if a channel was requested
|
||||
p->channel = nodeDB.getNodeChannel(p->to);
|
||||
LOG_DEBUG("localSend to channel %d\n", p->channel);
|
||||
|
||||
return send(p);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ bool NodeInfoModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes
|
||||
return false; // Let others look at this message also if they want
|
||||
}
|
||||
|
||||
void NodeInfoModule::sendOurNodeInfo(NodeNum dest, bool wantReplies)
|
||||
void NodeInfoModule::sendOurNodeInfo(NodeNum dest, bool wantReplies, uint8_t channel)
|
||||
{
|
||||
// cancel any not yet sent (now stale) position packets
|
||||
if (prevPacketId) // if we wrap around to zero, we'll simply fail to cancel in that rare case (no big deal)
|
||||
@ -38,6 +38,11 @@ void NodeInfoModule::sendOurNodeInfo(NodeNum dest, bool wantReplies)
|
||||
p->to = dest;
|
||||
p->decoded.want_response = wantReplies;
|
||||
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
||||
if (channel > 0) {
|
||||
LOG_DEBUG("sending ourNodeInfo to channel %d\n", channel);
|
||||
p->channel = channel;
|
||||
}
|
||||
|
||||
prevPacketId = p->id;
|
||||
|
||||
service.sendToMesh(p);
|
||||
|
@ -20,7 +20,7 @@ class NodeInfoModule : public ProtobufModule<meshtastic_User>, private concurren
|
||||
/**
|
||||
* Send our NodeInfo into the mesh
|
||||
*/
|
||||
void sendOurNodeInfo(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false);
|
||||
void sendOurNodeInfo(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false, uint8_t channel = 0);
|
||||
|
||||
protected:
|
||||
/** Called to handle a particular incoming message
|
||||
|
@ -120,7 +120,7 @@ meshtastic_MeshPacket *PositionModule::allocReply()
|
||||
return allocDataProtobuf(p);
|
||||
}
|
||||
|
||||
void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies)
|
||||
void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies, uint8_t channel)
|
||||
{
|
||||
// cancel any not yet sent (now stale) position packets
|
||||
if (prevPacketId) // if we wrap around to zero, we'll simply fail to cancel in that rare case (no big deal)
|
||||
@ -135,6 +135,9 @@ void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies)
|
||||
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
||||
prevPacketId = p->id;
|
||||
|
||||
if (channel > 0)
|
||||
p->channel = channel;
|
||||
|
||||
service.sendToMesh(p, RX_SRC_LOCAL, true);
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ class PositionModule : public ProtobufModule<meshtastic_Position>, private concu
|
||||
/**
|
||||
* Send our position into the mesh
|
||||
*/
|
||||
void sendOurPosition(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false);
|
||||
void sendOurPosition(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false, uint8_t channel = 0);
|
||||
|
||||
protected:
|
||||
/** Called to handle a particular incoming message
|
||||
|
Loading…
Reference in New Issue
Block a user