diff --git a/app/src/main/java/com/geeksville/mesh/model/RadioConfigViewModel.kt b/app/src/main/java/com/geeksville/mesh/model/RadioConfigViewModel.kt index 2e83b073..726bf919 100644 --- a/app/src/main/java/com/geeksville/mesh/model/RadioConfigViewModel.kt +++ b/app/src/main/java/com/geeksville/mesh/model/RadioConfigViewModel.kt @@ -13,13 +13,12 @@ import com.geeksville.mesh.IMeshService import com.geeksville.mesh.MeshProtos import com.geeksville.mesh.ModuleConfigProtos import com.geeksville.mesh.MyNodeInfo -import com.geeksville.mesh.NodeInfo import com.geeksville.mesh.Portnums import com.geeksville.mesh.Position import com.geeksville.mesh.R import com.geeksville.mesh.android.Logging import com.geeksville.mesh.config -import com.geeksville.mesh.database.entity.toNodeInfo +import com.geeksville.mesh.database.entity.NodeEntity import com.geeksville.mesh.deviceProfile import com.geeksville.mesh.moduleConfig import com.geeksville.mesh.repository.datastore.RadioConfigRepository @@ -70,12 +69,12 @@ class RadioConfigViewModel @Inject constructor( val connectionState get() = radioConfigRepository.connectionState private val _destNum = MutableStateFlow(null) - private val _destNode = MutableStateFlow(null) - val destNode: StateFlow get() = _destNode + private val _destNode = MutableStateFlow(null) + val destNode: StateFlow get() = _destNode /** - * Sets the destination [NodeInfo] used in Radio Configuration. - * @param num Destination nodeNum (or null for our local [NodeInfo]). + * Sets the destination [NodeEntity] used in Radio Configuration. + * @param num Destination nodeNum (or null for our local [NodeEntity]). */ fun setDestNum(num: Int?) { _destNum.value = num @@ -91,7 +90,7 @@ class RadioConfigViewModel @Inject constructor( init { combine(_destNum, radioConfigRepository.nodeDBbyNum) { destNum, nodes -> nodes[destNum] ?: nodes.values.firstOrNull() - }.onEach { _destNode.value = it?.toNodeInfo() }.launchIn(viewModelScope) + }.onEach { _destNode.value = it }.launchIn(viewModelScope) radioConfigRepository.deviceProfileFlow.onEach { _currentDeviceProfile.value = it @@ -110,6 +109,7 @@ class RadioConfigViewModel @Inject constructor( val hasPaFan: Boolean get() = destNode.value?.user?.hwModel in setOf( null, + MeshProtos.HardwareModel.UNRECOGNIZED, MeshProtos.HardwareModel.UNSET, MeshProtos.HardwareModel.BETAFPV_2400_TX, MeshProtos.HardwareModel.RADIOMASTER_900_BANDIT_NANO, @@ -367,12 +367,12 @@ class RadioConfigViewModel @Inject constructor( _deviceProfile.value = null meshService?.beginEditSettings() if (hasLongName() || hasShortName()) destNode.value?.user?.let { - val user = it.copy( - longName = if (hasLongName()) longName else it.longName, - shortName = if (hasShortName()) shortName else it.shortName, - hwModel = MeshProtos.HardwareModel.UNSET, - ) - if (it != user) setOwner(user.toProto()) + val user = MeshProtos.User.newBuilder() + .setLongName(if (hasLongName()) longName else it.longName) + .setShortName(if (hasShortName()) shortName else it.shortName) + .setIsLicensed(it.isLicensed) + .build() + if (it != user) setOwner(user) } if (hasChannelUrl()) try { setChannels(channelUrl) diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index 58b0b561..52dc68bc 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -1647,7 +1647,9 @@ class MeshService : Service(), Logging { debug("Sending our position/time to=$idNum ${Position(position)}") // Also update our own map for our nodeNum, by handling the packet just like packets from other users - handleReceivedPosition(mi.myNodeNum, position) + if (!localConfig.position.fixedPosition) { + handleReceivedPosition(mi.myNodeNum, position) + } sendToRadio(newMeshPacketTo(idNum).buildMeshPacket( channel = if (destNum == null) 0 else nodeDBbyNodeNum[destNum]?.channel ?: 0, @@ -1952,7 +1954,9 @@ class MeshService : Service(), Logging { removeFixedPosition = true } }) - handleReceivedPosition(destNum, pos) + updateNodeInfo(destNum) { + it.setPosition(pos, currentSecond()) + } } override fun requestTraceroute(requestId: Int, destNum: Int) = toRemoteExceptions { diff --git a/app/src/main/java/com/geeksville/mesh/ui/DeviceSettingsFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/DeviceSettingsFragment.kt index 70dccc5a..637836d6 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/DeviceSettingsFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/DeviceSettingsFragment.kt @@ -56,11 +56,11 @@ import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController -import com.geeksville.mesh.NodeInfo import com.geeksville.mesh.Position import com.geeksville.mesh.R import com.geeksville.mesh.android.Logging import com.geeksville.mesh.config +import com.geeksville.mesh.database.entity.NodeEntity import com.geeksville.mesh.model.Channel import com.geeksville.mesh.model.RadioConfigViewModel import com.geeksville.mesh.moduleConfig @@ -246,9 +246,10 @@ private fun MeshAppBar( ) } +@Suppress("LongMethod", "CyclomaticComplexMethod") @Composable fun RadioConfigNavHost( - node: NodeInfo?, + node: NodeEntity?, viewModel: RadioConfigViewModel = hiltViewModel(), navController: NavHostController = rememberNavController(), modifier: Modifier, @@ -413,13 +414,19 @@ fun RadioConfigNavHost( ) } composable(ConfigRoute.POSITION.name) { + val currentPosition = Position( + latitude = node?.latitude ?: 0.0, + longitude = node?.longitude ?: 0.0, + altitude = node?.position?.altitude ?: 0, + time = 1, // ignore time for fixed_position + ) PositionConfigItemList( - location = node?.position ?: Position(0.0, 0.0, 0), + location = currentPosition, positionConfig = radioConfigState.radioConfig.position, enabled = connected, onSaveClicked = { locationInput, positionInput -> if (positionInput.fixedPosition) { - if (locationInput != node?.position) { + if (locationInput != currentPosition) { viewModel.setFixedPosition(destNum, locationInput) } } else {