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 resp = reqwest::get("https://celestrak.org/NORAD/elements/gp.php?GROUP=stations&FORMAT=json").await.unwrap(); 16 17 let element_vec:Vec<sgp4::Elements> = resp.json().await.unwrap(); 18 19 20 let epoch = &element_vec[0].datetime.and_utc(); 21 22 let iss_constant = sgp4::Constants::from_elements(&element_vec[0]).unwrap(); 23 24 (Some(iss_constant),Some(*epoch)) 25 26} 27 28 29// i should be using the geoid crate but this is good enough for now 30pub fn polar_loc_transformer(loc: [f64;3]) -> [f32;2] { 31 let theta = -((loc[2]/ (loc[0].powi(2) + loc[1].powi(2) + loc[2].powi(2)).powf(0.5)).acos() - PI/2.0); 32 let phi = loc[1].signum() * (loc[0]/(loc[0].powi(2) + loc[1].powi(2)).powf(0.5)).acos(); 33 34 [(phi*180.0/PI) as f32, (theta*180.0/PI) as f32] 35 36 37} 38 39 40 41#[derive(Debug,Clone,PartialEq,Deserialize,Serialize)] 42pub struct Location { 43 pub latitude: String, 44 pub longitude: String 45} 46 47#[derive(Debug,Clone,Deserialize,Serialize)] 48pub struct FLocation { 49 pub latitude: f32, 50 pub longitude: f32 51} 52 53 54 55 56impl From<Location> for FLocation { 57 fn from(value: Location) -> Self { 58 FLocation { 59 longitude: value.longitude.parse().unwrap(), 60 latitude: value.latitude.parse().unwrap() 61 } 62 } 63 64} 65 66#[derive(Debug,Clone,PartialEq,Deserialize,Serialize)] 67pub struct LocationResponse { 68 pub iss_position: Location, 69 message: String, 70 timestamp: i64 71} 72