mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Added satellite visibility parameter to SatPos.kt #62
This commit is contained in:
1 parent
4ee74a6789
commit
ae08c7c937
17 files changed
+202
-137
No files matched your search
@@ -61,8 +61,8 @@ class SettingsManager @Inject constructor(private val prefs: SharedPreferences)
|
||||
|
||||
override fun saveStationPosition(position: GeoPos) {
|
||||
prefs.edit {
|
||||
putString(keyLatitude, position.latitude.toString())
|
||||
putString(keyLongitude, position.longitude.toString())
|
||||
putString(keyLatitude, position.lat.toString())
|
||||
putString(keyLongitude, position.lon.toString())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ class SettingsManager @Inject constructor(private val prefs: SharedPreferences)
|
||||
}
|
||||
|
||||
override fun getHoursAhead(): Int {
|
||||
return prefs.getInt(keyHoursAhead, 8)
|
||||
return prefs.getInt(keyHoursAhead, 24)
|
||||
}
|
||||
|
||||
override fun setHoursAhead(hoursAhead: Int) {
|
||||
|
||||
@@ -119,7 +119,7 @@ class MapFragment : Fragment(R.layout.fragment_map) {
|
||||
setInfoWindow(null)
|
||||
setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM)
|
||||
icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_position)
|
||||
position = GeoPoint(stationPos.latitude, stationPos.longitude)
|
||||
position = GeoPoint(stationPos.lat, stationPos.lon)
|
||||
mapView.overlays[0] = this
|
||||
mapView.invalidate()
|
||||
}
|
||||
@@ -135,7 +135,7 @@ class MapFragment : Fragment(R.layout.fragment_map) {
|
||||
setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER)
|
||||
icon = getCustomTextIcon(it.key.data.name)
|
||||
try {
|
||||
position = GeoPoint(it.value.latitude, it.value.longitude)
|
||||
position = GeoPoint(it.value.lat, it.value.lon)
|
||||
} catch (exception: IllegalArgumentException) {
|
||||
println(exception.stackTraceToString())
|
||||
}
|
||||
@@ -165,10 +165,10 @@ class MapFragment : Fragment(R.layout.fragment_map) {
|
||||
}
|
||||
|
||||
private fun handleTrack(satTrack: List<List<GeoPos>>) {
|
||||
val center = GeoPoint(satTrack[0][0].latitude, satTrack[0][0].longitude)
|
||||
val center = GeoPoint(satTrack[0][0].lat, satTrack[0][0].lon)
|
||||
val trackOverlay = FolderOverlay()
|
||||
satTrack.forEach { track ->
|
||||
val trackPoints = track.map { GeoPoint(it.latitude, it.longitude) }
|
||||
val trackPoints = track.map { GeoPoint(it.lat, it.lon) }
|
||||
Polyline().apply {
|
||||
try {
|
||||
setPoints(trackPoints)
|
||||
@@ -184,12 +184,7 @@ class MapFragment : Fragment(R.layout.fragment_map) {
|
||||
}
|
||||
|
||||
private fun handleFootprint(satPos: SatPos) {
|
||||
val center = GeoPoint(Math.toDegrees(satPos.latitude), Math.toDegrees(satPos.longitude))
|
||||
val radiusM = satPos.getRangeCircleRadiusKm() * 1000
|
||||
val footprintPoints = mutableListOf<GeoPoint>()
|
||||
for (i in 0..720) {
|
||||
footprintPoints.add(center.destinationPoint(radiusM, i.toDouble()))
|
||||
}
|
||||
val footprintPoints = satPos.getRangeCircle().map { GeoPoint(it.lat, it.lon) }
|
||||
val footprintOverlay = Polyline().apply {
|
||||
outlinePaint.set(footprintPaint)
|
||||
try {
|
||||
@@ -210,9 +205,9 @@ class MapFragment : Fragment(R.layout.fragment_map) {
|
||||
mapDataDst.text = String.format(getString(R.string.map_distance), mapData.range)
|
||||
mapDataVel.text = String.format(getString(R.string.map_velocity), mapData.velocity)
|
||||
mapDataLat.text =
|
||||
String.format(getString(R.string.map_latitude), mapData.osmPos.latitude)
|
||||
String.format(getString(R.string.map_latitude), mapData.osmPos.lat)
|
||||
mapDataLon.text =
|
||||
String.format(getString(R.string.map_longitude), mapData.osmPos.longitude)
|
||||
String.format(getString(R.string.map_longitude), mapData.osmPos.lon)
|
||||
}
|
||||
binding.mapView.invalidate()
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.rtbishop.look4sat.domain.predict.GeoPos
|
||||
import com.rtbishop.look4sat.domain.predict.SatPos
|
||||
import com.rtbishop.look4sat.domain.predict.Satellite
|
||||
import com.rtbishop.look4sat.utility.QthConverter
|
||||
import com.rtbishop.look4sat.utility.toDegrees
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.*
|
||||
import java.util.*
|
||||
@@ -46,8 +47,8 @@ class MapViewModel @Inject constructor(
|
||||
private lateinit var selectedSatellite: Satellite
|
||||
|
||||
val stationPos = liveData {
|
||||
val osmLat = clipLat(stationPosition.latitude)
|
||||
val osmLon = clipLon(stationPosition.longitude)
|
||||
val osmLat = clipLat(stationPosition.lat)
|
||||
val osmLon = clipLon(stationPosition.lon)
|
||||
emit(GeoPos(osmLat, osmLon))
|
||||
}
|
||||
|
||||
@@ -116,23 +117,23 @@ class MapViewModel @Inject constructor(
|
||||
val endDate = Date(date.time + (satellite.orbitalPeriod * 2.4 * 60000L).toLong())
|
||||
var oldLongitude = 0.0
|
||||
satelliteManager.getTrack(satellite, pos, date.time, endDate.time).forEach { satPos ->
|
||||
val osmLat = clipLat(Math.toDegrees(satPos.latitude))
|
||||
val osmLon = clipLon(Math.toDegrees(satPos.longitude))
|
||||
val osmLat = clipLat(satPos.latitude.toDegrees())
|
||||
val osmLon = clipLon(satPos.longitude.toDegrees())
|
||||
val currentPosition = GeoPos(osmLat, osmLon)
|
||||
if (oldLongitude < -170.0 && currentPosition.longitude > 170.0) {
|
||||
if (oldLongitude < -170.0 && currentPosition.lon > 170.0) {
|
||||
// adding left terminal position
|
||||
currentTrack.add(GeoPos(osmLat, -180.0))
|
||||
val finishedTrack = mutableListOf<GeoPos>().apply { addAll(currentTrack) }
|
||||
satTracks.add(finishedTrack)
|
||||
currentTrack.clear()
|
||||
} else if (oldLongitude > 170.0 && currentPosition.longitude < -170.0) {
|
||||
} else if (oldLongitude > 170.0 && currentPosition.lon < -170.0) {
|
||||
// adding right terminal position
|
||||
currentTrack.add(GeoPos(osmLat, 180.0))
|
||||
val finishedTrack = mutableListOf<GeoPos>().apply { addAll(currentTrack) }
|
||||
satTracks.add(finishedTrack)
|
||||
currentTrack.clear()
|
||||
}
|
||||
oldLongitude = currentPosition.longitude
|
||||
oldLongitude = currentPosition.lon
|
||||
currentTrack.add(currentPosition)
|
||||
}
|
||||
satTracks.add(currentTrack)
|
||||
@@ -143,8 +144,8 @@ class MapViewModel @Inject constructor(
|
||||
val positions = mutableMapOf<Satellite, GeoPos>()
|
||||
satellites.forEach { satellite ->
|
||||
val satPos = satelliteManager.getPosition(satellite, pos, date.time)
|
||||
val osmLat = clipLat(Math.toDegrees(satPos.latitude))
|
||||
val osmLon = clipLon(Math.toDegrees(satPos.longitude))
|
||||
val osmLat = clipLat(satPos.latitude.toDegrees())
|
||||
val osmLon = clipLon(satPos.longitude.toDegrees())
|
||||
positions[satellite] = GeoPos(osmLat, osmLon)
|
||||
}
|
||||
_positions.postValue(positions)
|
||||
@@ -157,10 +158,10 @@ class MapViewModel @Inject constructor(
|
||||
|
||||
private suspend fun getSatData(satellite: Satellite, pos: GeoPos, date: Date) {
|
||||
val satPos = satelliteManager.getPosition(satellite, pos, date.time)
|
||||
val osmLat = clipLat(Math.toDegrees(satPos.latitude))
|
||||
val osmLon = clipLon(Math.toDegrees(satPos.longitude))
|
||||
val osmLat = clipLat(satPos.latitude.toDegrees())
|
||||
val osmLon = clipLon(satPos.longitude.toDegrees())
|
||||
val osmPos = GeoPos(osmLat, osmLon)
|
||||
val qthLoc = QthConverter.positionToQth(osmPos.latitude, osmPos.longitude) ?: "-- --"
|
||||
val qthLoc = QthConverter.positionToQth(osmPos.lat, osmPos.lon) ?: "-- --"
|
||||
val satData = MapData(
|
||||
satellite, satellite.data.catnum, satellite.data.name, satPos.distance,
|
||||
satPos.altitude, satPos.getOrbitalVelocity(), qthLoc, osmPos
|
||||
|
||||
@@ -54,7 +54,7 @@ class FilterDialog : AppCompatDialogFragment() {
|
||||
val hoursAhead = try {
|
||||
filterHoursEdit.text.toString().toInt()
|
||||
} catch (exception: Exception) {
|
||||
8
|
||||
24
|
||||
}
|
||||
val minElevation = try {
|
||||
filterElevEdit.text.toString().toDouble()
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.rtbishop.look4sat.R
|
||||
import com.rtbishop.look4sat.databinding.FragmentRadarBinding
|
||||
import com.rtbishop.look4sat.domain.predict.SatPass
|
||||
import com.rtbishop.look4sat.domain.predict.SatPos
|
||||
import com.rtbishop.look4sat.utility.toDegrees
|
||||
import com.rtbishop.look4sat.utility.toTimerString
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@@ -121,8 +122,8 @@ class RadarFragment : Fragment(R.layout.fragment_radar) {
|
||||
val radarAlt = getString(R.string.radar_alt_value)
|
||||
val radarDist = getString(R.string.radar_dist_value)
|
||||
val radarId = getString(R.string.radar_sat_id)
|
||||
radarAzValue.text = String.format(radarAzim, Math.toDegrees(satPos.azimuth))
|
||||
radarElValue.text = String.format(radarElev, Math.toDegrees(satPos.elevation))
|
||||
radarAzValue.text = String.format(radarAzim, satPos.azimuth.toDegrees())
|
||||
radarElValue.text = String.format(radarElev, satPos.elevation.toDegrees())
|
||||
radarAltValue.text = String.format(radarAlt, satPos.altitude)
|
||||
radarDstValue.text = String.format(radarDist, satPos.distance)
|
||||
radarSatId.text = String.format(radarId, satPass.catNum)
|
||||
|
||||
@@ -22,7 +22,10 @@ import android.graphics.*
|
||||
import android.view.View
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.rtbishop.look4sat.R
|
||||
import com.rtbishop.look4sat.domain.predict.PI_2
|
||||
import com.rtbishop.look4sat.domain.predict.SatPos
|
||||
import com.rtbishop.look4sat.domain.predict.TWO_PI
|
||||
import com.rtbishop.look4sat.utility.toRadians
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.min
|
||||
import kotlin.math.sin
|
||||
@@ -31,7 +34,6 @@ class RadarView(context: Context) : View(context) {
|
||||
|
||||
private val defaultColor = ContextCompat.getColor(context, R.color.accent)
|
||||
private val scale = resources.displayMetrics.density
|
||||
private val piDiv2 = Math.PI / 2.0
|
||||
private val strokeSize = scale * 2f
|
||||
private var position: SatPos? = null
|
||||
private var positions: List<SatPos> = emptyList()
|
||||
@@ -186,8 +188,8 @@ class RadarView(context: Context) : View(context) {
|
||||
}
|
||||
|
||||
private fun drawCrosshair(canvas: Canvas, azimuth: Float, pitch: Float, radarRadius: Float) {
|
||||
val azimuthRad = Math.toRadians(azimuth.toDouble())
|
||||
val tmpElevation = Math.toRadians(pitch.toDouble())
|
||||
val azimuthRad = azimuth.toDouble().toRadians()
|
||||
val tmpElevation = pitch.toDouble().toRadians()
|
||||
val elevationRad = if (tmpElevation > 0.0) 0.0 else tmpElevation
|
||||
val crossX = sph2CartX(azimuthRad, -elevationRad, radarRadius.toDouble())
|
||||
val crossY = sph2CartY(azimuthRad, -elevationRad, radarRadius.toDouble())
|
||||
@@ -197,13 +199,13 @@ class RadarView(context: Context) : View(context) {
|
||||
}
|
||||
|
||||
private fun sph2CartX(azimuth: Double, elevation: Double, r: Double): Float {
|
||||
val radius = r * (piDiv2 - elevation) / piDiv2
|
||||
return (radius * cos(piDiv2 - azimuth)).toFloat()
|
||||
val radius = r * (PI_2 - elevation) / PI_2
|
||||
return (radius * cos(PI_2 - azimuth)).toFloat()
|
||||
}
|
||||
|
||||
private fun sph2CartY(azimuth: Double, elevation: Double, r: Double): Float {
|
||||
val radius = r * (piDiv2 - elevation) / piDiv2
|
||||
return (radius * sin(piDiv2 - azimuth)).toFloat()
|
||||
val radius = r * (PI_2 - elevation) / PI_2
|
||||
return (radius * sin(PI_2 - azimuth)).toFloat()
|
||||
}
|
||||
|
||||
private fun createPassTrajectory(radarRadius: Float) {
|
||||
@@ -221,7 +223,7 @@ class RadarView(context: Context) : View(context) {
|
||||
private fun createPassTrajectoryArrow() {
|
||||
val radius = beaconSize
|
||||
val sides = 3
|
||||
val angle = 2.0 * Math.PI / sides
|
||||
val angle = TWO_PI / sides
|
||||
arrowPath.moveTo((radius * cos(angle)).toFloat(), (radius * sin(angle)).toFloat())
|
||||
for (i in 1 until sides) {
|
||||
val x = (radius * cos(angle - angle * i)).toFloat()
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.rtbishop.look4sat.domain.predict.SatPos
|
||||
import com.rtbishop.look4sat.framework.OrientationManager
|
||||
import com.rtbishop.look4sat.utility.DataReporter
|
||||
import com.rtbishop.look4sat.utility.round
|
||||
import com.rtbishop.look4sat.utility.toDegrees
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.isActive
|
||||
@@ -81,8 +82,8 @@ class RadarViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
private fun getMagDeclination(geoPos: GeoPos, time: Long = System.currentTimeMillis()): Float {
|
||||
val latitude = geoPos.latitude.toFloat()
|
||||
val longitude = geoPos.longitude.toFloat()
|
||||
val latitude = geoPos.lat.toFloat()
|
||||
val longitude = geoPos.lon.toFloat()
|
||||
return GeomagneticField(latitude, longitude, 0f, time).declination
|
||||
}
|
||||
|
||||
@@ -99,8 +100,8 @@ class RadarViewModel @Inject constructor(
|
||||
if (settings.getRotatorEnabled()) {
|
||||
val server = settings.getRotatorServer()
|
||||
val port = settings.getRotatorPort().toInt()
|
||||
val azimuth = Math.toDegrees(satPos.azimuth).round(1)
|
||||
val elevation = Math.toDegrees(satPos.elevation).round(1)
|
||||
val azimuth = satPos.azimuth.toDegrees().round(1)
|
||||
val elevation = satPos.elevation.toDegrees().round(1)
|
||||
reporter.reportRotation(server, port, azimuth, elevation)
|
||||
}
|
||||
_passData.postValue(RadarData(satPos, satTrack))
|
||||
|
||||
+2
-2
@@ -49,8 +49,8 @@ class PositionDialog : AppCompatDialogFragment() {
|
||||
WindowManager.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
val location = preferences.loadStationPosition()
|
||||
positionLatEdit.setText(location.latitude.toString())
|
||||
positionLonEdit.setText(location.longitude.toString())
|
||||
positionLatEdit.setText(location.lat.toString())
|
||||
positionLonEdit.setText(location.lon.toString())
|
||||
positionBtnPos.setOnClickListener {
|
||||
val latitude = try {
|
||||
positionLatEdit.text.toString().toDouble()
|
||||
|
||||
+2
-2
@@ -209,8 +209,8 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
binding.run {
|
||||
val latFormat = getString(R.string.location_lat)
|
||||
val lonFormat = getString(R.string.location_lon)
|
||||
settingsLocation.locationLat.text = String.format(latFormat, geoPos.latitude)
|
||||
settingsLocation.locationLon.text = String.format(lonFormat, geoPos.longitude)
|
||||
settingsLocation.locationLat.text = String.format(latFormat, geoPos.lat)
|
||||
settingsLocation.locationLon.text = String.format(lonFormat, geoPos.lon)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user