Skip to content

Commit

Permalink
Fix default stance in position_precision
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-bennett committed Feb 24, 2024
1 parent 730429f commit c2085c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/mesh/Channels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ void Channels::initDefaultChannel(ChannelIndex chIndex)
channelSettings.psk.size = 1;
strncpy(channelSettings.name, "", sizeof(channelSettings.name));
channelSettings.module_settings.position_precision = 32; // default to sending location on the primary channel
channelSettings.has_module_settings = true;

ch.has_settings = true;
ch.role = meshtastic_Channel_Role_PRIMARY;
Expand Down
20 changes: 16 additions & 4 deletions src/modules/PositionModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ bool PositionModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes
}

nodeDB.updatePosition(getFrom(&mp), p);
precision = channels.getByIndex(mp.channel).settings.module_settings.position_precision;
if (channels.getByIndex(mp.channel).settings.has_module_settings) {
precision = channels.getByIndex(mp.channel).settings.module_settings.position_precision;
} else if (channels.getByIndex(mp.channel).role == meshtastic_Channel_Role_PRIMARY) {
precision = 32;
} else {
precision = 0;
}

return false; // Let others look at this message also if they want
}
Expand Down Expand Up @@ -117,8 +123,8 @@ meshtastic_MeshPacket *PositionModule::allocReply()

// We want the imprecise position to be the middle of the possible location, not
if (precision < 31 && precision > 1) {
p.latitude_i += (1 << 31 - precision);
p.longitude_i += (1 << 31 - precision);
p.latitude_i += (1 << (31 - precision));
p.longitude_i += (1 << (31 - precision));
}
p.precision_bits = precision;
p.time = localPosition.time;
Expand Down Expand Up @@ -217,7 +223,13 @@ void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies, uint8_t cha
service.cancelSending(prevPacketId);

// Set's the class precision value for this particular packet
precision = channels.getByIndex(channel).settings.module_settings.position_precision;
if (channels.getByIndex(channel).settings.has_module_settings) {
precision = channels.getByIndex(channel).settings.module_settings.position_precision;
} else if (channels.getByIndex(channel).role == meshtastic_Channel_Role_PRIMARY) {
precision = 32;
} else {
precision = 0;
}

meshtastic_MeshPacket *p = allocReply();
if (p == nullptr) {
Expand Down

0 comments on commit c2085c2

Please sign in to comment.