-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp.js
77 lines (61 loc) · 2.49 KB
/
temp.js
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
var satellite = require('satellite.js');
var fs = require('fs');
var updatingDebris = false;
const debrisData = [];
const EARTH_RADIUS = 6378.137;
// Function to load/update debris data
function updateDebris() {
if (updatingDebris) return;
updatingDebris = true;
try {
// Read the contents of the local 'latest.json' file
//fixed path issue using relative path
var latestData = fs.readFileSync('latest.json', 'utf8');
var obj = JSON.parse(latestData);
//console.log(obj);
if (obj.i && obj.i.t > 0) {
debrisData.splice(0, debrisData.length);
for (var i in obj.l) {
var tleName = obj.l[i][0];
var tleLine1 = obj.l[i][1];
var tleLine2 = obj.l[i][2];
var tleLine3 = obj.l[i][3]; // color
var tleLine4 = obj.l[i][4]; // size
var satrec = satellite.twoline2satrec(tleLine1, tleLine2);
if (satrec.error) {
///throw new Exception('Can't create a valid satrec.');
continue;
}
var curTime = new Date();
var positionEci = satellite.propagate(satrec, curTime).position;
if (!positionEci) {
//throw an Exception('Can't create an ECI position.');
continue;
}
var gmst = satellite.gstime(curTime);
var positionGd = satellite.eciToGeodetic(positionEci, gmst);
var altitude = positionGd.height / EARTH_RADIUS;
var longitudeDeg = satellite.degreesLong(positionGd.longitude);
var latitudeDeg = satellite.degreesLat(positionGd.latitude);
debrisData.push({
name: tleName,
lat: latitudeDeg,
lng: longitudeDeg,
alt: altitude,
// we have not radius data, so we use an (adequate) random value
radius: Math.random() * 0.1 + parseFloat(tleLine4),
color: tleLine3,
satrec: satrec
});
console.log(debrisData);
}
return debrisData;
} else {
console.log('No debris data in response.');
}
} catch (ex) {
console.log(ex);
} finally {
updatingDebris = false;
}
}