feat: complete Satellite Telemetry Display

This commit is contained in:
angelina-tsuboi
2023-05-07 11:42:18 -07:00
parent 50824ee83b
commit d60a1f8871
5 changed files with 61 additions and 49 deletions

View File

@@ -12,4 +12,8 @@ Made by Angelina Tsuboi (G4LXY)
# APIS
- space-track.org
- n2yo.com/api
- n2yo.com/api
# TODO
- map layout

2
go.mod
View File

@@ -12,9 +12,11 @@ require (
github.com/lucasb-eyer/go-colorful v1.0.3 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mazznoer/colorgrad v0.8.1 // indirect
github.com/mazznoer/csscolorparser v0.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect

4
go.sum
View File

@@ -140,12 +140,16 @@ github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0V
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mazznoer/colorgrad v0.8.1 h1:Bw/ks+KujOOg9E6YQvPqSqTLryiFnwliAH5VMZarSTI=
github.com/mazznoer/colorgrad v0.8.1/go.mod h1:xCjvoNkXHJIAPOUMSMrXkFdxTGQqk8zMYS3e5hSLghA=
github.com/mazznoer/csscolorparser v0.1.0 h1:xUf1uzU1r24JleIIb2Kz3bl7vATStxy53gm67yuPP+c=
github.com/mazznoer/csscolorparser v0.1.0/go.mod h1:Aj22+L/rYN/Y6bj3bYqO3N6g1dtdHtGfQ32xZ5PJQic=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

View File

@@ -5,16 +5,12 @@ import (
"fmt"
"github.com/iskaa02/qalam/gradient"
"encoding/json"
"github.com/TwiN/go-color"
"net/http"
"strconv"
"os"
)
type Marker struct {
X int
Y int
}
// Satellite Position Visualization Code
func SatellitePositionVisualization() {
options, _ := ioutil.ReadFile("txt/orbital_element.txt")
opt,_:=gradient.NewGradient("#1179ef", "cyan")
@@ -28,14 +24,13 @@ func SatellitePositionVisualization() {
return
}
// PrintNORADInfo(extractNorad(result), result)
GetLocation(extractNorad(result))
} else if (selection == 2) {
fmt.Print("\n ENTER NORAD ID > ")
var norad string
fmt.Scanln(&norad)
PrintNORADInfo(norad, "UNSPECIFIED")
GetLocation(norad)
}
return
@@ -43,16 +38,26 @@ func SatellitePositionVisualization() {
// Show visualization and info in box
func GetLocation(norad string) {
// fmt.Print("\n ENTER LATITUDE > ")
// var latitude string
// fmt.Print("\n ENTER LONGITUDE > ")
// var longitude string
// fmt.Print("\n ENTER ALTITUDE > ")
// var altitude string
fmt.Print("\n ENTER LATITUDE > ")
var latitude string
fmt.Scanln(&latitude)
fmt.Print("\n ENTER LONGITUDE > ")
var longitude string
fmt.Scanln(&longitude)
fmt.Print("\n ENTER ALTITUDE > ")
var altitude string
fmt.Scanln(&altitude)
// marker := getXYfromLonLat(strconv.Atoi(latitude, longitude))
_, err := strconv.ParseFloat(latitude, 64)
_, err2 := strconv.ParseFloat(longitude, 64)
_, err3 := strconv.Atoi(altitude)
url := "https://api.n2yo.com/rest/v1/satellite/positions/25544/41.702/-76.014/0/2/&apiKey=46REG9-PS2V7M-H3B76Q-5103"
if err != nil || err2 != nil || err3 != nil {
fmt.Println(color.Ize(color.Red, " [!] ERROR: INVALID INPUT"))
return
}
url := "https://api.n2yo.com/rest/v1/satellite/positions/" + norad + "/" + latitude + "/" + longitude + "/" + altitude + "/2/&apiKey=" + os.Getenv("N2YO_API_KEY")
resp, err := http.Get(url)
if err != nil {
fmt.Println(err)
@@ -65,41 +70,38 @@ func GetLocation(norad string) {
fmt.Println(err)
}
fmt.Printf("Satellite Name: %s\n", data.SatelliteInfo.Satname)
fmt.Printf("Satellite ID: %d\n", data.SatelliteInfo.Satid)
fmt.Println(color.Ize(color.Purple, "\n╔═════════════════════════════════════════════════════════════╗"))
fmt.Println(color.Ize(color.Purple, "║ Satellite Information ║"))
fmt.Println(color.Ize(color.Purple, "╠═════════════════════════════════════════════════════════════╣"))
for _, pos := range data.Positions {
fmt.Printf("Latitude: %f\n", pos.Satlatitude)
fmt.Printf("Longitude: %f\n", pos.Satlongitude)
fmt.Printf("Altitude: %f\n", pos.Sataltitude)
fmt.Printf("Azimuth: %f\n", pos.Azimuth)
fmt.Printf("Elevation: %f\n", pos.Elevation)
fmt.Printf("RA: %f\n", pos.Ra)
fmt.Printf("Dec: %f\n", pos.Dec)
fmt.Printf("Timestamp: %d\n", pos.Timestamp)
fmt.Println("------------------------")
fmt.Println(color.Ize(color.Purple, GenRowString("Satellite Name", data.SatelliteInfo.Satname)))
fmt.Println(color.Ize(color.Purple, GenRowString("Satellite ID", fmt.Sprintf("%d", data.SatelliteInfo.Satid))))
// fmt.Println(color.Ize(color.Purple, "║ ║"))
fmt.Println(color.Ize(color.Purple, "╠═════════════════════════════════════════════════════════════╣"))
fmt.Println(color.Ize(color.Purple, "║ Satellite Positions ║"))
fmt.Println(color.Ize(color.Purple, "╠═════════════════════════════════════════════════════════════╣"))
for in, pos := range data.Positions {
PrintSatellitePosition(pos, in == len(data.Positions) - 1)
}
}
func DisplayMap() {
// TODO
}
func getXYfromLonLat(lat int, lon int) Marker {
marker := Marker{}
// Normalise the X, Y in their min -> max space
normalX := (lat + 219) / (293 + 219);
normalY := (lon + 244) / (266 + 244);
// Stretch them to match the ASCII map
const width = 70
const height = 42
realX := normalX * width - 3;
realY := normalY * height - 9;
marker.X = realX
marker.Y = realY
return marker
}
func PrintSatellitePosition (pos Position, last bool) {
fmt.Println(color.Ize(color.Purple, GenRowString("Latitude", fmt.Sprintf("%f", pos.Satlatitude))))
fmt.Println(color.Ize(color.Purple, GenRowString("Longitude", fmt.Sprintf("%f", pos.Satlongitude))))
fmt.Println(color.Ize(color.Purple, GenRowString("Altitude", fmt.Sprintf("%f", pos.Sataltitude))))
fmt.Println(color.Ize(color.Purple, GenRowString("Right Ascension", fmt.Sprintf("%f", pos.Azimuth))))
fmt.Println(color.Ize(color.Purple, GenRowString("Satellite Declination", fmt.Sprintf("%f", pos.Dec))))
fmt.Println(color.Ize(color.Purple, GenRowString("Timestamp", fmt.Sprintf("%d", pos.Timestamp))))
if (last) {
fmt.Println(color.Ize(color.Purple, "╚═════════════════════════════════════════════════════════════╝\n\n"))
} else {
fmt.Println(color.Ize(color.Purple, "╠═════════════════════════════════════════════════════════════╣"))
}
}

View File

@@ -2,7 +2,7 @@
[ 1 ] Orbital Element Data Display
[ 2 ] Satellite Position Visualization
[ 2 ] Satellite Telemetry Display
[ 3 ] Orbital Predictions (Visual, Radio, and SGP4)