-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSatControlProcess.cs
213 lines (181 loc) · 6.77 KB
/
SatControlProcess.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SGPdotNET.TLE;
using SGPdotNET.Observation;
using SGPdotNET.CoordinateSystem;
using System.Collections;
using System.Timers;
using SGPdotNET.Util;
using System.Net;
using System.IO;
using System.Text.Json;
using System.Configuration;
namespace SDRSharp.Plugin.SatControl
{
public class SatControlProcess
{
private Dictionary<int, Tle> tles;
private Satellite sat;
private GroundStation gs;
public TopocentricObservation observation;
public event Action satRefresh;
Timer timer;
AppSettingsSection config = ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetExecutingAssembly().Location).AppSettings;
public Dictionary<int, TransmitterDetail> transmitterSelected;
public ArrayList transmitterSelectedDisplay;
public SatInfo satInfo;
public class TransmitterDetail
{
//public string uuid;
public string description { get; set; }
//public bool alive;
//public string type { get; set; }
public Nullable<double> uplink_low { get; set; }
public Nullable<double> uplink_high { get; set; }
//public long uplink_drift;
public Nullable<double> downlink_low { get; set; }
public Nullable<double> downlink_high { get; set; }
//public long downlink_drift;
public string mode { get; set; }
public Nullable<double> mode_id { get; set; }
public string uplink_mode { get; set; }
public bool invert { get; set; }
public Nullable<double> baud { get; set; }
//public string sat_id;
public Nullable<uint> norad_cat_id { get; set; }
//public string status;
//public string updated;
//public string citation;
//public string service;
//public string coordination;
//public string coordination_url;
}
public class SatInfo
{
public TimeSpan deltaTime { get; set; }
public DateTime aos { get; set; }
public double MaxEl { get; set; }
}
public SatControlProcess()
{
// download Transmitter Data
try
{
WebClient Client = new WebClient();
//Client.DownloadFile("https://db.satnogs.org/api/tle/?format=json", @"tle.json");
Client.DownloadFile("https://db.satnogs.org/api/transmitters/?format=json", @"transmitters.json");
}
catch(Exception ex)
{
}
// Remote URL
var url = new Uri("https://celestrak.com/NORAD/elements/amateur.txt");
// Create a provider whose cache is renewed every 12 hours
var provider = new CachingRemoteTleProvider(true, TimeSpan.FromHours(12), "tle.txt", url);
//var provider = new RemoteTleProvider(true, url);
// Get every TLE
tles = provider.GetTles();
timer = new Timer();
timer.Interval = 1000;
timer.Elapsed += Timer_Elapsed;
satInfo = new SatInfo();
// Set up our ground station location
var lat = Convert.ToDouble(config.Settings["QTH_Latitude"].Value);
var lon = Convert.ToDouble(config.Settings["QTH_Lontitude"].Value);
var location = new GeodeticCoordinate(Angle.FromDegrees(lat), Angle.FromDegrees(lon), 0.11);
gs = new GroundStation(location);
transmitterSelected = new Dictionary<int, TransmitterDetail>();
transmitterSelectedDisplay = new ArrayList();
}
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
// Observe the satellite
DateTime startTime = new DateTime(
DateTime.UtcNow.Year
, DateTime.UtcNow.Month
, DateTime.UtcNow.Day
, DateTime.UtcNow.Hour
, DateTime.UtcNow.Minute
, DateTime.UtcNow.Second
, DateTimeKind.Utc
);
DateTime endTime = new DateTime(
DateTime.UtcNow.Year
, DateTime.UtcNow.Month
, DateTime.UtcNow.Day
, DateTime.UtcNow.Hour
, DateTime.UtcNow.Minute
, DateTime.UtcNow.Second
, DateTimeKind.Utc
).AddDays(1);
TimeSpan tp = endTime - startTime;
observation = gs.Observe(sat, startTime);
List<SatelliteVisibilityPeriod> sv = gs.Observe(sat, startTime, endTime, TimeSpan.FromSeconds(10));
if (sv.Count > 0)
{
if (sv[0].Start > startTime)
{
satInfo.deltaTime = sv[0].Start - startTime;
}
else
{
satInfo.deltaTime = sv[0].End - startTime;
}
satInfo.MaxEl = sv[0].MaxElevation.Degrees;
}
satRefresh?.Invoke();
}
// list all satellite
public ArrayList getSatelliteList()
{
ArrayList satnames = new ArrayList();
foreach (KeyValuePair<int, Tle> tle in tles)
{
satnames.Add(tle.Value.Name);
}
return satnames;
}
public void connectSatellite(int satIndex)
{
// Create a satellite from the TLEs
Tle tle = tles.ElementAt(satIndex).Value;
sat = new Satellite(tle);
readTransmitterData(sat.Tle.NoradNumber);
}
private void readTransmitterData(uint satid)
{
string fileName = "transmitters.json";
string jsonString = File.ReadAllText(fileName);
TransmitterDetail[] txDetails = JsonSerializer.Deserialize<TransmitterDetail[]>(jsonString);
transmitterSelected.Clear();
transmitterSelectedDisplay.Clear();
int index = 0;
foreach (TransmitterDetail txDetail in txDetails)
{
if(txDetail.norad_cat_id==satid)
{
transmitterSelected.Add(index, txDetail);
transmitterSelectedDisplay.Add(txDetail.description);
}
index++;
}
}
public void serviceStart()
{
if (timer.Enabled != true)
{
timer.Start();
}
}
public void serviceStop()
{
if (timer.Enabled == true)
{
timer.Stop();
}
}
}
}