kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
refactor: enable remote admin to set/remove `fixed_position`
rodzic
f8898def89
commit
852c6e1bc2
|
@ -121,6 +121,9 @@ interface IMeshService {
|
|||
/// Send position packet with wantResponse to nodeNum
|
||||
void requestPosition(in int destNum, in Position position);
|
||||
|
||||
/// Send setFixedPosition admin packet (or removeFixedPosition if Position is empty)
|
||||
void setFixedPosition(in int destNum, in Position position);
|
||||
|
||||
/// Send traceroute packet with wantResponse to nodeNum
|
||||
void requestTraceroute(in int requestId, in int destNum);
|
||||
|
||||
|
|
|
@ -271,15 +271,15 @@ class RadioConfigViewModel @Inject constructor(
|
|||
"Request NodeDB reset error"
|
||||
)
|
||||
|
||||
fun setFixedPosition(position: Position) {
|
||||
fun setFixedPosition(destNum: Int, position: Position) {
|
||||
try {
|
||||
meshService?.requestPosition(myNodeNum ?: return, position)
|
||||
meshService?.setFixedPosition(destNum, position)
|
||||
} catch (ex: RemoteException) {
|
||||
errormsg("Request position error: ${ex.message}")
|
||||
errormsg("Set fixed position error: ${ex.message}")
|
||||
}
|
||||
}
|
||||
|
||||
fun removeFixedPosition() = setFixedPosition(Position(0.0, 0.0, 0))
|
||||
fun removeFixedPosition(destNum: Int) = setFixedPosition(destNum, Position(0.0, 0.0, 0))
|
||||
|
||||
// Set the radio config (also updates our saved copy in preferences)
|
||||
fun setConfig(config: ConfigProtos.Config) {
|
||||
|
|
|
@ -1850,31 +1850,31 @@ class MeshService : Service(), Logging {
|
|||
})
|
||||
|
||||
}
|
||||
|
||||
override fun requestPosition(destNum: Int, position: Position) = toRemoteExceptions {
|
||||
if (destNum != myNodeNum) {
|
||||
// request position
|
||||
sendToRadio(newMeshPacketTo(destNum).buildMeshPacket(
|
||||
channel = nodeDBbyNodeNum[destNum]?.channel ?: 0,
|
||||
priority = MeshPacket.Priority.BACKGROUND,
|
||||
) {
|
||||
portnumValue = Portnums.PortNum.POSITION_APP_VALUE
|
||||
wantResponse = true
|
||||
})
|
||||
} else {
|
||||
// send fixed position (local only/no remote method)
|
||||
sendToRadio(newMeshPacketTo(destNum).buildAdminPacket {
|
||||
if (position != Position(0.0, 0.0, 0)) {
|
||||
setFixedPosition = position {
|
||||
latitudeI = Position.degI(position.latitude)
|
||||
longitudeI = Position.degI(position.longitude)
|
||||
altitude = position.altitude
|
||||
}
|
||||
.also { sendPosition(it) } // TODO remove after minDeviceVersion >= 2.3.3
|
||||
} else {
|
||||
removeFixedPosition = true
|
||||
}
|
||||
})
|
||||
sendToRadio(newMeshPacketTo(destNum).buildMeshPacket(
|
||||
channel = nodeDBbyNodeNum[destNum]?.channel ?: 0,
|
||||
priority = MeshPacket.Priority.BACKGROUND,
|
||||
) {
|
||||
portnumValue = Portnums.PortNum.POSITION_APP_VALUE
|
||||
wantResponse = true
|
||||
})
|
||||
}
|
||||
|
||||
override fun setFixedPosition(destNum: Int, position: Position) = toRemoteExceptions {
|
||||
val pos = position {
|
||||
latitudeI = Position.degI(position.latitude)
|
||||
longitudeI = Position.degI(position.longitude)
|
||||
altitude = position.altitude
|
||||
}
|
||||
sendToRadio(newMeshPacketTo(destNum).buildAdminPacket {
|
||||
if (position != Position(0.0, 0.0, 0)) {
|
||||
setFixedPosition = pos
|
||||
} else {
|
||||
removeFixedPosition = true
|
||||
}
|
||||
})
|
||||
handleReceivedPosition(destNum, pos)
|
||||
}
|
||||
|
||||
override fun requestTraceroute(requestId: Int, destNum: Int) = toRemoteExceptions {
|
||||
|
|
|
@ -413,19 +413,18 @@ fun RadioConfigNavHost(
|
|||
}
|
||||
composable(ConfigRoute.POSITION.name) {
|
||||
PositionConfigItemList(
|
||||
isLocal = isLocal,
|
||||
location = node?.position,
|
||||
positionConfig = radioConfigState.radioConfig.position,
|
||||
enabled = connected,
|
||||
onSaveClicked = { locationInput, positionInput ->
|
||||
if (positionInput.fixedPosition) {
|
||||
if (locationInput != null && locationInput != node?.position) {
|
||||
viewModel.setFixedPosition(locationInput)
|
||||
viewModel.setFixedPosition(destNum, locationInput)
|
||||
}
|
||||
} else {
|
||||
if (radioConfigState.radioConfig.position.fixedPosition) {
|
||||
// fixed position changed from enabled to disabled
|
||||
viewModel.removeFixedPosition()
|
||||
viewModel.removeFixedPosition(destNum)
|
||||
}
|
||||
}
|
||||
val config = config { position = positionInput }
|
||||
|
|
|
@ -25,7 +25,6 @@ import com.geeksville.mesh.ui.components.SwitchPreference
|
|||
|
||||
@Composable
|
||||
fun PositionConfigItemList(
|
||||
isLocal: Boolean = false,
|
||||
location: Position?,
|
||||
positionConfig: PositionConfig,
|
||||
enabled: Boolean,
|
||||
|
@ -94,7 +93,7 @@ fun PositionConfigItemList(
|
|||
item {
|
||||
EditTextPreference(title = "Latitude",
|
||||
value = locationInput?.latitude ?: 0.0,
|
||||
enabled = enabled && isLocal,
|
||||
enabled = enabled,
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onValueChanged = { value ->
|
||||
if (value >= -90 && value <= 90.0)
|
||||
|
@ -104,7 +103,7 @@ fun PositionConfigItemList(
|
|||
item {
|
||||
EditTextPreference(title = "Longitude",
|
||||
value = locationInput?.longitude ?: 0.0,
|
||||
enabled = enabled && isLocal,
|
||||
enabled = enabled,
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onValueChanged = { value ->
|
||||
if (value >= -180 && value <= 180.0)
|
||||
|
@ -114,7 +113,7 @@ fun PositionConfigItemList(
|
|||
item {
|
||||
EditTextPreference(title = "Altitude (meters)",
|
||||
value = locationInput?.altitude ?: 0,
|
||||
enabled = enabled && isLocal,
|
||||
enabled = enabled,
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onValueChanged = { value ->
|
||||
locationInput?.let { locationInput = it.copy(altitude = value) }
|
||||
|
|
Ładowanie…
Reference in New Issue