Satellite tracking TUI using ratatui
1use std::f64::consts::PI;
2
3use chrono::{DateTime,Utc};
4use serde::{Deserialize,Serialize};
5
6
7pub fn earth_rotation_angle(t_u:f64) -> f64 {
8 //returns radians
9 2.0*PI*(0.7790572732640 + 1.00273781191135448*t_u) % std::f64::consts::TAU
10}
11
12
13//to be deleted dont think i need it much longer?
14pub async fn get_celerak_data() -> (Option<sgp4::Constants>,Option<DateTime<Utc>>) {
15 let mut resp = ureq::get("https://celestrak.org/NORAD/elements/gp.php?GROUP=stations&FORMAT=json").call().unwrap();
16 //blocking, and thats okey.
17
18 let element_vec:Vec<sgp4::Elements> = resp.body_mut().read_json().unwrap();
19
20
21 let epoch = &element_vec[0].datetime.and_utc();
22
23 let iss_constant = sgp4::Constants::from_elements(&element_vec[0]).unwrap();
24
25 (Some(iss_constant),Some(*epoch))
26
27}
28
29
30// i should be using the geoid crate but this is good enough for now
31pub fn polar_loc_transformer(loc: [f64;3]) -> [f32;2] {
32 let theta = -((loc[2]/ (loc[0].powi(2) + loc[1].powi(2) + loc[2].powi(2)).powf(0.5)).acos() - PI/2.0);
33 let phi = loc[1].signum() * (loc[0]/(loc[0].powi(2) + loc[1].powi(2)).powf(0.5)).acos();
34
35 [(phi*180.0/PI) as f32, (theta*180.0/PI) as f32]
36
37
38}
39
40
41
42#[derive(Debug,Clone,PartialEq,Deserialize,Serialize)]
43pub struct Location {
44 pub latitude: String,
45 pub longitude: String
46}
47
48#[derive(Debug,Clone,Deserialize,Serialize)]
49pub struct FLocation {
50 pub latitude: f32,
51 pub longitude: f32
52}
53
54
55
56
57impl From<Location> for FLocation {
58 fn from(value: Location) -> Self {
59 FLocation {
60 longitude: value.longitude.parse().unwrap(),
61 latitude: value.latitude.parse().unwrap()
62 }
63 }
64
65}
66
67#[derive(Debug,Clone,PartialEq,Deserialize,Serialize)]
68pub struct LocationResponse {
69 pub iss_position: Location,
70 message: String,
71 timestamp: i64
72}
73