Fix default stance in position_precision

This commit is contained in:
Jonathan Bennett 2024-02-24 12:53:46 -06:00
parent 730429fc9b
commit c2085c2c88
2 changed files with 17 additions and 4 deletions

View File

@ -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;

View File

@ -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
}
@ -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;
@ -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) {