-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathcatalog-loader.ts
1079 lines (947 loc) · 38 KB
/
catalog-loader.ts
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* eslint-disable max-lines */
import { getEl } from '@app/lib/get-el';
import { StringPad } from '@app/lib/stringPad';
import type { CatalogManager } from '@app/singletons/catalog-manager';
import { MissileObject } from '@app/singletons/catalog-manager/MissileObject';
import { errorManagerInstance } from '@app/singletons/errorManager';
import { CruncerMessageTypes, CruncherSat } from '@app/webworker/positionCruncher';
import {
BaseObject,
CatalogSource,
DetailedSatellite,
DetailedSensor,
LandObject,
Marker,
Sensor,
SpaceObjectType,
Star,
Tle,
TleLine1,
TleLine2,
} from 'ootk';
import { keepTrackApi } from '../keepTrackApi';
import { SettingsManager } from '../settings/settings';
interface JsSat {
TLE1: string;
TLE2: string;
vmag?: number;
}
interface ExtraSat {
ON?: string;
OT?: SpaceObjectType;
SCC: string;
TLE1: string;
TLE2: string;
vmag?: number;
}
interface AsciiTleSat {
ON?: string;
OT?: SpaceObjectType;
SCC: string;
TLE1: TleLine1;
TLE2: TleLine2;
}
export interface KeepTrackTLEFile {
/** First TLE line */
TLE1: TleLine1;
/** Second TLE line */
TLE2: TleLine2;
/** Satellite Bus */
bus?: string;
/** Lift vehicle configuration */
configuration?: string;
/** Owner country of the object */
country?: string;
/** Length of the object in meters */
length?: string;
/** Size of the object's diameter in meters */
diameter?: string;
/** Size of the object's width in meters */
span?: string;
/** Dry mass of the object in kilograms */
dryMass?: string;
/** Equipment on the object */
equipment?: string;
/** Date launched into space in YYYY-MM-DD */
launchDate?: string;
/**
* Stable Date in YYYY-MM-DD.
* This is mainly for identifying fragment creation dates
*/
stableDate?: string;
/** Launch mass including fuel in kilograms */
launchMass?: string;
/** Launch site */
launchSite?: string;
/** Launch Pad */
launchPad?: string;
/** Launch vehicle */
launchVehicle?: string;
/** Lifetime of the object in years */
lifetime?: string | number;
/** Manufacturer of the object */
manufacturer?: string;
/** Mission of the object */
mission?: string;
/** Motor of the object */
motor?: string;
/** Primary Name of the object */
name: string;
/** Alternate name of the object */
altName?: string;
/** Owner of the object */
owner?: string;
/** Payload of the object */
payload?: string;
/** Power information */
power?: string;
/** Purpose of the object */
purpose?: string;
/** Size of the object in Radar Cross Section (RCS) in meters squared */
rcs?: string;
/** Shape of the object */
shape?: string;
/** Current status of the object */
status?: string;
/** Type of the object */
type?: SpaceObjectType;
/** Visual magnitude of the object */
vmag?: number;
/**
* Used internally only and deleted before saving
* @deprecated Not really, but it makes it clear that this is not saved to disk
*/
JCAT?: string;
altId?: string;
/** This is added in addSccNum_ */
sccNum?: string;
/** This is added in parseIntlDes_ */
intlDes?: string;
/** This is added in this file */
active?: boolean;
/** This is added in this file */
source?: CatalogSource;
/** This is added in this file */
id?: number;
}
export class CatalogLoader {
static filterTLEDatabase(resp: KeepTrackTLEFile[], limitSatsArray?: string[], extraSats?: ExtraSat[], asciiCatalog?: AsciiTleSat[] | void, jsCatalog?: JsSat[]): void {
let tempObjData: BaseObject[] = [];
const catalogManagerInstance = keepTrackApi.getCatalogManager();
catalogManagerInstance.sccIndex = <{ [key: string]: number }>{};
catalogManagerInstance.cosparIndex = <{ [key: string]: number }>{};
CatalogLoader.checkForLimitSats_(limitSatsArray);
const notionalSatNum = 400000; // Start at 400,000 to avoid conflicts with real satellites
for (let i = 0; i < resp.length; i++) {
CatalogLoader.addSccNum_(resp, i);
// Check if first digit is a letter
resp[i].sccNum = Tle.convertA5to6Digit(resp[i]?.sccNum);
if (settingsManager.limitSats === '') {
CatalogLoader.processAllSats_(resp, i, catalogManagerInstance, tempObjData, notionalSatNum);
} else {
CatalogLoader.processLimitedSats_(limitSatsArray, resp, i, catalogManagerInstance, tempObjData);
}
}
if (extraSats?.length > 0) {
CatalogLoader.processExtraSats_(extraSats, catalogManagerInstance, tempObjData);
}
if (asciiCatalog && asciiCatalog?.length > 0) {
tempObjData = CatalogLoader.processAsciiCatalog_(asciiCatalog, catalogManagerInstance, tempObjData);
}
if (jsCatalog?.length > 0) {
CatalogLoader.processJsCatalog_(jsCatalog, catalogManagerInstance, tempObjData);
}
CatalogLoader.addNonSatelliteObjects_(catalogManagerInstance, tempObjData);
catalogManagerInstance.objectCache = tempObjData;
}
/**
* This function will load the catalog, additional catalogs, and merge them together.
*
* Primary Catalogs
* 1. tle.json - this contains extended object information including launch location and RCS.
* 2. tleDebris.json - this contains all non-payload data from TLE.json
* Secondary Catalogs
* 1. extra.json - this contains supplemental information about the catalog in json format.
* 2. TLE.txt - this contains a local ASCII TLE file.
* 3. externalTLEs - this contains an external TLE file.
* 4. vimpel.json - this contains JSC Vimpel TLE data.
*
* The catalog is loaded in the above order appending/overwriting the information each step of the way.
*
* If a file is missing, the function will skip it and continue loading the next file.
*
* If all files are missing, the function will return an error.
*/
static async load(): Promise<void> {
const settingsManager: SettingsManager = window.settingsManager;
try {
const {
extraSats,
asciiCatalog,
jsCatalog,
externalCatalog,
}: { extraSats: Promise<ExtraSat[]>; asciiCatalog: Promise<AsciiTleSat[] | void>; jsCatalog: Promise<JsSat[]>; externalCatalog: Promise<AsciiTleSat[] | void> } =
CatalogLoader.getAdditionalCatalogs_(settingsManager);
if (settingsManager.externalTLEsOnly) {
// Load our database for the extra information - the satellites will be filtered out
await fetch(settingsManager.dataSources.tle)
.then((response) => response.json())
.then((data) => CatalogLoader.parse({
keepTrackTle: data,
externalCatalog,
}))
.catch((error) => {
errorManagerInstance.error(error, 'tleManagerInstance.loadCatalog');
});
} else if (settingsManager.isUseDebrisCatalog) {
// Load the debris catalog
await fetch(settingsManager.dataSources.tleDebris)
.then((response) => response.json())
.then((data) => CatalogLoader.parse({
keepTrackTle: data,
keepTrackExtra: extraSats,
keepTrackAscii: asciiCatalog,
vimpelCatalog: jsCatalog,
}))
.catch((error) => {
errorManagerInstance.error(error, 'tleManagerInstance.loadCatalog');
});
} else {
// Load the primary catalog
await fetch(settingsManager.dataSources.tle)
.then((response) => response.json())
.then((data) => CatalogLoader.parse({
keepTrackTle: data,
keepTrackExtra: extraSats,
keepTrackAscii: asciiCatalog,
externalCatalog,
vimpelCatalog: jsCatalog,
}))
.catch(async (error) => {
if (error.message === 'Failed to fetch') {
errorManagerInstance.warn('Failed to download latest catalog! Using offline catalog which may be out of date!');
await fetch(`${settingsManager.installDirectory}tle/tle.json`)
.then((response) => response.json())
.then((data) => CatalogLoader.parse({
keepTrackTle: data,
keepTrackExtra: extraSats,
keepTrackAscii: asciiCatalog,
externalCatalog,
vimpelCatalog: jsCatalog,
}));
} else {
errorManagerInstance.error(error, 'tleManagerInstance.loadCatalog');
}
});
}
} catch (e) {
errorManagerInstance.warn('Failed to load TLE catalog(s)!');
}
}
/**
* Parses the satellite catalog data and filters TLEs based on the given parameters.
* @param resp - An array of SatObject containing the satellite catalog data.
* @param extraSats - A Promise that resolves to an array of ExtraSat objects.
* @param altCatalog - An object containing alternate catalogs. It has the following properties:
* - asciiCatalog: A Promise that resolves to an array of AsciiTleSat objects.
* - externalCatalog: (optional) A Promise that resolves to an array of AsciiTleSat objects or void.
* @param jsCatalog - A Promise that resolves to an array of JsSat objects.
*/
static async parse({
keepTrackTle: resp = [],
keepTrackExtra: extraSats = Promise.resolve([]),
keepTrackAscii: asciiCatalog = Promise.resolve([]),
externalCatalog = Promise.resolve([]),
vimpelCatalog: jsCatalog = Promise.resolve([]),
}: {
keepTrackTle?: KeepTrackTLEFile[];
keepTrackExtra?: Promise<ExtraSat[]>;
keepTrackAscii?: Promise<AsciiTleSat[] | void>;
externalCatalog?: Promise<AsciiTleSat[] | void>;
vimpelCatalog?: Promise<JsSat[]>;
}): Promise<void> {
await Promise.all([extraSats, asciiCatalog, externalCatalog, jsCatalog]).then(([extraSats, asciiCatalog, externalCatalog, jsCatalog]) => {
asciiCatalog = externalCatalog || asciiCatalog;
const limitSatsArray = !settingsManager.limitSats ? CatalogLoader.setupGetVariables() : settingsManager.limitSats.split(',');
// Make sure everyone agrees on what time it is
keepTrackApi.getTimeManager().synchronize();
/*
* Filter TLEs
* Sets catalogManagerInstance.satData internally to reduce memory usage
*/
CatalogLoader.filterTLEDatabase(resp, limitSatsArray, extraSats, asciiCatalog, jsCatalog);
const catalogManagerInstance = keepTrackApi.getCatalogManager();
catalogManagerInstance.numObjects = catalogManagerInstance.objectCache.length;
const satDataString = CatalogLoader.getSatDataString_(catalogManagerInstance.objectCache);
/** Send satDataString to satCruncher to begin propagation loop */
catalogManagerInstance.satCruncher.postMessage({
typ: CruncerMessageTypes.OBJ_DATA,
dat: satDataString,
fieldOfViewSetLength: catalogManagerInstance.fieldOfViewSet.length,
isLowPerf: settingsManager.lowPerf,
});
});
}
/**
* Parses GET variables for SatCruncher initialization
* @returns An array of strings containing the limitSats values
*/
static setupGetVariables() {
let limitSatsArray: string[] = [];
/** Parses GET variables for SatCruncher initialization */
// This should be somewhere else!!
const queryStr = window.location.search.substring(1);
const params = queryStr.split('&');
for (const param of params) {
const key = param.split('=')[0];
const val = param.split('=')[1];
switch (key) {
case 'limitSats':
settingsManager.limitSats = val;
(<HTMLInputElement>getEl('limitSats')).value = val;
getEl('limitSats-Label').classList.add('active');
limitSatsArray = val.split(',');
break;
case 'future use':
default:
break;
}
}
return limitSatsArray;
}
/**
* Adds non-satellite objects to the catalog manager instance.
* @param catalogManagerInstance - The catalog manager instance to add the objects to.
* @param tempObjData - An array of temporary satellite data.
*/
private static addNonSatelliteObjects_(catalogManagerInstance: CatalogManager, tempObjData: BaseObject[]) {
catalogManagerInstance.orbitalSats = tempObjData.length + settingsManager.maxAnalystSats;
const dotsManagerInstance = keepTrackApi.getDotsManager();
dotsManagerInstance.starIndex1 = catalogManagerInstance.starIndex1 + catalogManagerInstance.orbitalSats;
dotsManagerInstance.starIndex2 = catalogManagerInstance.starIndex2 + catalogManagerInstance.orbitalSats;
let i = 0;
for (const staticSat of catalogManagerInstance.staticSet) {
staticSat.id = tempObjData.length;
catalogManagerInstance.staticSet[i].id = tempObjData.length;
i++;
if (staticSat.maxRng) {
const sensor = new DetailedSensor({
id: tempObjData.length,
...staticSat,
});
tempObjData.push(sensor);
} else {
const landObj = new LandObject({
id: tempObjData.length,
...staticSat,
});
tempObjData.push(landObj);
}
}
for (const analSat of catalogManagerInstance.analSatSet) {
analSat.id = tempObjData.length;
tempObjData.push(analSat);
}
catalogManagerInstance.numSatellites = tempObjData.length;
for (const missileObj of catalogManagerInstance.missileSet) {
tempObjData.push(missileObj);
}
catalogManagerInstance.missileSats = tempObjData.length; // This is the start of the missiles index
for (const fieldOfViewMarker of catalogManagerInstance.fieldOfViewSet) {
fieldOfViewMarker.id = tempObjData.length;
const marker = new Marker(fieldOfViewMarker);
tempObjData.push(marker);
}
}
/**
* Checks if there are any limit sats and sets the settingsManager accordingly.
* @param limitSatsArray - An array of limit sats.
*/
private static checkForLimitSats_(limitSatsArray: string[]) {
if (typeof limitSatsArray === 'undefined' || limitSatsArray.length === 0 || limitSatsArray[0] === null) {
// If there are no limits then just process like normal
settingsManager.limitSats = '';
}
}
/**
* Removes any extra lines and \r characters from the given string array.
* @param content - The string array to be cleaned.
*/
private static cleanAsciiCatalogFile_(content: string[]) {
// Check for extra line at the end of the file
if (content[content.length - 1] === '') {
content.pop();
}
// Remove any \r characters
for (let i = 0; i < content.length; i++) {
content[i] = content[i].replace('\r', '');
}
}
/**
* Fix missing zeros in the SCC number
*
* TODO: This should be done by the catalog-manager itself
*/
private static addSccNum_(resp: KeepTrackTLEFile[], i: number) {
resp[i].sccNum = StringPad.pad0(resp[i].TLE1.substring(2, 7).trim(), 5);
// Also update TLE1
resp[i].TLE1 = <TleLine1>(resp[i].TLE1.substring(0, 2) + resp[i].sccNum + resp[i].TLE1.substring(7));
// Also update TLE2
resp[i].TLE2 = <TleLine2>(resp[i].TLE2.substring(0, 2) + resp[i].sccNum + resp[i].TLE2.substring(7));
}
/**
* Returns an object containing promises for extraSats, asciiCatalog, jsCatalog, and externalCatalog.
* @param settingsManager - The settings manager object.
* @returns An object containing promises for extraSats, asciiCatalog, jsCatalog, and externalCatalog.
*/
private static getAdditionalCatalogs_(settingsManager: SettingsManager) {
let extraSats: Promise<ExtraSat[]> = null;
let externalCatalog: Promise<AsciiTleSat[] | void> = null;
let asciiCatalog: Promise<AsciiTleSat[]> = null;
let jsCatalog: Promise<JsSat[]> = null;
if (settingsManager.offline && !settingsManager.isDisableExtraCatalog) {
extraSats = CatalogLoader.getExtraCatalog_(settingsManager);
}
if (!settingsManager.externalTLEs && !settingsManager.isDisableAsciiCatalog) {
asciiCatalog = CatalogLoader.getAsciiCatalog_(settingsManager);
}
if (settingsManager.isEnableJscCatalog) {
jsCatalog = CatalogLoader.getJscCatalog_(settingsManager);
}
if (settingsManager.externalTLEs) {
externalCatalog = CatalogLoader.getExternalCatalog_(settingsManager);
}
return { extraSats, asciiCatalog, jsCatalog, externalCatalog };
}
/**
* Retrieves the ASCII catalog from the TLE.txt file in the install directory.
* @param settingsManager - The settings manager instance.
* @returns An array of AsciiTleSat objects representing the catalog.
*/
private static async getAsciiCatalog_(settingsManager: SettingsManager) {
const asciiCatalog: AsciiTleSat[] = [];
const resp = await fetch(`${settingsManager.installDirectory}tle/TLE.txt`);
if (resp.ok) {
const asciiCatalogFile = await resp.text();
const content = asciiCatalogFile.split('\n');
for (let i = 0; i < content.length; i += 2) {
asciiCatalog.push({
SCC: StringPad.pad0(content[i].substring(2, 7).trim(), 5),
TLE1: <TleLine1>content[i],
TLE2: <TleLine2>content[i + 1],
});
}
// Sort asciiCatalog by SCC
CatalogLoader.sortByScc_(asciiCatalog);
}
return asciiCatalog;
}
/**
* Asynchronously retrieves an external catalog of satellite TLEs from a URL specified in the settingsManager.
* @param {SettingsManager} settingsManager - The settings manager containing the URL for the external TLEs.
* @returns {Promise<AsciiTleSat[]>} - A promise that resolves to an array of AsciiTleSat objects representing the satellite TLEs.
*/
// eslint-disable-next-line require-await
private static async getExternalCatalog_(settingsManager: SettingsManager): Promise<AsciiTleSat[] | void> {
return fetch(settingsManager.externalTLEs)
.then((resp) => {
if (resp.ok) {
const externalCatalog: AsciiTleSat[] = [];
return resp.text().then((data) => {
const content = data.split('\n');
// Check if last line is empty and remove it if so
CatalogLoader.cleanAsciiCatalogFile_(content);
if (content[0].startsWith('1 ')) {
CatalogLoader.parseAsciiTLE_(content, externalCatalog);
} else if (content[1].startsWith('1 ')) {
CatalogLoader.parseAscii3LE_(content, externalCatalog);
} else {
errorManagerInstance.warn('External TLEs are not in the correct format');
}
CatalogLoader.sortByScc_(externalCatalog);
return externalCatalog;
});
}
errorManagerInstance.warn(`Error loading external TLEs from ${settingsManager.externalTLEs}`);
errorManagerInstance.info('Reverting to internal TLEs');
settingsManager.externalTLEs = '';
return [];
})
.catch(() => {
errorManagerInstance.warn(`Error loading external TLEs from ${settingsManager.externalTLEs}`);
errorManagerInstance.info('Reverting to internal TLEs');
settingsManager.externalTLEs = '';
});
}
/**
* Retrieves the extra catalog from the specified install directory.
* @param settingsManager - The settings manager instance.
* @returns A promise that resolves to an array of ExtraSat objects.
*/
private static async getExtraCatalog_(settingsManager: SettingsManager): Promise<ExtraSat[]> {
return (await fetch(`${settingsManager.installDirectory}tle/extra.json`)).json().catch(() => {
errorManagerInstance.warn('Error loading extra.json');
});
}
/**
* Retrieves the JsSat catalog from the specified settings manager.
* @param settingsManager - The settings manager to retrieve the catalog from.
* @returns A promise that resolves to an array of JsSat objects.
*/
// eslint-disable-next-line require-await
private static async getJscCatalog_(settingsManager: SettingsManager): Promise<JsSat[]> {
return fetch(settingsManager.dataSources.vimpel)
.then((response) => {
if (response.ok) {
return response.json();
}
errorManagerInstance.warn('Error loading vimpel.json');
return [];
})
.catch(() => {
errorManagerInstance.warn('Error loading vimpel.json');
});
}
/**
* Consolidate the satData into a string to send to satCruncher
*
* There is a lot of extra data that we don't need to send to satCruncher.
*/
private static getSatDataString_(objData: BaseObject[]) {
return JSON.stringify(
objData.map((obj) => {
let data: CruncherSat;
// Order matters here
if (obj.isSatellite()) {
data = {
tle1: (obj as DetailedSatellite).tle1,
tle2: (obj as DetailedSatellite).tle2,
active: obj.active,
};
} else if (obj.isMissile()) {
data = {
latList: (obj as MissileObject).latList,
lonList: (obj as MissileObject).lonList,
altList: (obj as MissileObject).altList,
};
} else if (obj.isStar()) {
data.ra = (obj as Star).ra;
data.dec = (obj as Star).dec;
} else if (obj.isMarker()) {
data = {
isMarker: true,
};
} else if ((obj as Sensor | LandObject).isStatic()) {
data = {
lat: (obj as Sensor | LandObject).lat,
lon: (obj as Sensor | LandObject).lon,
alt: (obj as Sensor | LandObject).alt,
};
} else {
throw new Error('Unknown object type');
}
return data;
}),
);
}
private static makeDebris(notionalDebris: any, meanAnom: number, notionalSatNum: number, tempSatData: BaseObject[]) {
const debris = { ...notionalDebris };
debris.id = tempSatData.length;
debris.sccNum = notionalSatNum.toString();
if (notionalSatNum < 1300000) {
/*
* ESA estimates 1300000 objects larger than 1cm
* Random number between 0.01 and 0.1
*/
debris.rcs = 0.01 + Math.random() * 0.09;
} else {
// Random number between 0.001 and 0.01
debris.name = `${notionalDebris.name} (1mm Notional)`; // 1mm
debris.rcs = 0.001 + Math.random() * 0.009;
}
notionalSatNum++;
meanAnom = parseFloat(debris.TLE2.substr(43, 51)) + meanAnom;
if (meanAnom > 360) {
meanAnom -= 360;
}
if (meanAnom < 0) {
meanAnom += 360;
}
debris.TLE2 =
debris.TLE2.substr(0, 17) + // Columns 1-18
StringPad.pad0((Math.random() * 360).toFixed(4), 8) + // New RAAN
debris.TLE2.substr(25, 18) + // Columns 25-44
StringPad.pad0(meanAnom.toFixed(4), 8) + // New Mean Anomaly
debris.TLE2.substr(51); // Columns 51-69
tempSatData.push(debris);
}
private static parseAscii3LE_(content: string[], externalCatalog: AsciiTleSat[]) {
for (let i = 0; i < content.length; i += 3) {
externalCatalog.push({
SCC: StringPad.pad0(content[i + 1].substring(2, 7).trim(), 5),
ON: content[i].trim(),
TLE1: <TleLine1>content[i + 1],
TLE2: <TleLine2>content[i + 2],
});
}
}
private static parseAsciiTLE_(content: string[], externalCatalog: AsciiTleSat[]) {
for (let i = 0; i < content.length; i += 2) {
externalCatalog.push({
SCC: StringPad.pad0(content[i].substring(2, 7).trim(), 5),
TLE1: <TleLine1>content[i],
TLE2: <TleLine2>content[i + 1],
});
}
}
private static parseIntlDes_(TLE1: string) {
let year = TLE1.substring(9, 17).trim().substring(0, 2); // clean up intl des for display
if (year === '') {
errorManagerInstance.debug(`intlDes is empty for ${TLE1}`);
return 'None';
}
if (isNaN(parseInt(year))) {
// eslint-disable-next-line no-debugger
debugger;
}
const prefix = parseInt(year) > 50 ? '19' : '20';
year = prefix + year;
const rest = TLE1.substring(9, 17).trim().substring(2);
return `${year}-${rest}`;
}
private static processAllSats_(resp: KeepTrackTLEFile[], i: number, catalogManagerInstance: CatalogManager, tempObjData: BaseObject[], notionalSatNum: number): void {
if (settingsManager.isStarlinkOnly && resp[i].name.indexOf('STARLINK') === -1) {
return;
}
const intlDes = CatalogLoader.parseIntlDes_(resp[i].TLE1);
resp[i].intlDes = intlDes;
resp[i].active = true;
if (!settingsManager.isDebrisOnly || (settingsManager.isDebrisOnly && (resp[i].type === 2 || resp[i].type === 3))) {
resp[i].id = tempObjData.length;
const source = Tle.classification(resp[i].TLE1);
switch (source) {
case 'U':
resp[i].source = CatalogSource.USSF;
break;
case 'C':
resp[i].source = CatalogSource.CELESTRAK;
break;
case 'M':
resp[i].source = CatalogSource.UNIV_OF_MICH;
break;
case 'V':
resp[i].source = CatalogSource.VIMPEL;
break;
default:
// Default to USSF for now
resp[i].source = CatalogSource.USSF;
}
let rcs: number;
rcs = resp[i].rcs === 'LARGE' ? 5 : rcs;
rcs = resp[i].rcs === 'MEDIUM' ? 0.5 : rcs;
rcs = resp[i].rcs === 'SMALL' ? 0.05 : rcs;
rcs = resp[i].rcs && !isNaN(parseFloat(resp[i].rcs)) ? parseFloat(resp[i].rcs) : rcs ?? null;
// Never fail just because of one bad satellite
let isAddedToCatalog = false;
try {
const satellite = new DetailedSatellite({
id: tempObjData.length,
tle1: resp[i].TLE1,
tle2: resp[i].TLE2,
...resp[i],
rcs,
});
tempObjData.push(satellite);
isAddedToCatalog = true;
} catch (e) {
errorManagerInstance.log(e);
}
if (isAddedToCatalog) {
catalogManagerInstance.sccIndex[`${resp[i].sccNum}`] = tempObjData.length - 1;
catalogManagerInstance.cosparIndex[`${resp[i].intlDes}`] = tempObjData.length - 1;
}
}
if (settingsManager.isNotionalDebris && resp[i].type === 3) {
const notionalDebris = new DetailedSatellite({
id: 0,
name: `${resp[i].name} (1cm Notional)`,
tle1: resp[i].TLE1,
tle2: resp[i].TLE2,
sccNum: '',
type: SpaceObjectType.NOTIONAL,
source: 'Notional',
active: true,
});
for (let i = 0; i < 8; i++) {
if (tempObjData.length > settingsManager.maxNotionalDebris) {
break;
}
CatalogLoader.makeDebris(notionalDebris, 15 + Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, -15 - Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, 30 + Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, -30 - Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, 45 + Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, -45 - Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, 60 + Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, -60 - Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, 75 + Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, -75 - Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, 90 + Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, -90 - Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, 105 + Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, -105 - Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, 120 + Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, -120 - Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, 135 + Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, -135 - Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, 150 + Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, -150 - Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, 165 + Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, -165 - Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, 180 + Math.random() * 15, notionalSatNum, tempObjData);
CatalogLoader.makeDebris(notionalDebris, -180 - Math.random() * 15, notionalSatNum, tempObjData);
}
}
}
private static processAsciiCatalogKnown_(catalogManagerInstance: CatalogManager, element: AsciiTleSat, tempSatData: DetailedSatellite[]) {
const i = catalogManagerInstance.sccIndex[`${element.SCC}`];
tempSatData[i].tle1 = element.TLE1;
tempSatData[i].tle2 = element.TLE2;
tempSatData[i].name = element.ON || tempSatData[i].name || 'Unknown';
tempSatData[i].source = settingsManager.externalTLEs ? settingsManager.externalTLEs.split('/')[2] : CatalogSource.TLE_TXT;
tempSatData[i].altId = 'EXTERNAL_SAT'; // TODO: This is a hack to make sure the satellite is not removed by the filter
const satellite = new DetailedSatellite(tempSatData[i]);
tempSatData[i] = satellite;
}
private static processAsciiCatalogUnknown_(element: AsciiTleSat, tempSatData: BaseObject[], catalogManagerInstance: CatalogManager) {
if (typeof element.ON === 'undefined') {
element.ON = 'Unknown';
}
if (typeof element.OT === 'undefined') {
element.OT = SpaceObjectType.SPECIAL;
}
const intlDes = this.parseIntlDes_(element.TLE1);
const sccNum = Tle.convertA5to6Digit(element.SCC.toString());
const asciiSatInfo = {
static: false,
missile: false,
active: true,
name: parseInt(sccNum) >= 90000 && parseInt(sccNum) <= 99999 ? `Analyst ${sccNum}` : element.ON,
type: element.OT,
country: 'Unknown',
rocket: 'Unknown',
site: 'Unknown',
sccNum,
tle1: element.TLE1,
tle2: element.TLE2,
source: settingsManager.externalTLEs ? settingsManager.externalTLEs.split('/')[2] : CatalogSource.TLE_TXT,
intlDes,
typ: 'sat', // TODO: What is this?
id: tempSatData.length,
};
catalogManagerInstance.sccIndex[`${sccNum.toString()}`] = tempSatData.length;
catalogManagerInstance.cosparIndex[`${intlDes}`] = tempSatData.length;
const satellite = new DetailedSatellite({
tle1: asciiSatInfo.tle1,
tle2: asciiSatInfo.tle2,
...asciiSatInfo,
});
satellite.id = tempSatData.length;
satellite.altId = 'EXTERNAL_SAT'; // TODO: This is a hack to make sure the satellite is not removed by the filter
tempSatData.push(satellite);
}
private static processAsciiCatalog_(asciiCatalog: AsciiTleSat[], catalogManagerInstance: CatalogManager, tempSatData: any[]) {
if (settingsManager.externalTLEs) {
errorManagerInstance.info(`Processing ${settingsManager.externalTLEs}`);
} else {
errorManagerInstance.log('Processing ASCII Catalog');
}
// If asciiCatalog catalogue
for (const element of asciiCatalog) {
if (!element.TLE1 || !element.TLE2) {
continue;
} // Don't Process Bad Satellite Information
// See if we know anything about it already
if (typeof catalogManagerInstance.sccIndex[`${element.SCC}`] !== 'undefined') {
CatalogLoader.processAsciiCatalogKnown_(catalogManagerInstance, element, tempSatData);
} else {
CatalogLoader.processAsciiCatalogUnknown_(element, tempSatData, catalogManagerInstance);
}
}
if (settingsManager.externalTLEs) {
if (settingsManager.externalTLEsOnly) {
tempSatData = tempSatData.filter((sat) => {
if (sat.altId === 'EXTERNAL_SAT') {
console.log(sat);
return true;
}
return false;
});
}
catalogManagerInstance.sccIndex = <{ [key: string]: number }>{};
catalogManagerInstance.cosparIndex = <{ [key: string]: number }>{};
for (let idx = 0; idx < tempSatData.length; idx++) {
tempSatData[idx].id = idx;
catalogManagerInstance.sccIndex[`${tempSatData[idx].sccNum}`] = idx;
catalogManagerInstance.cosparIndex[`${tempSatData[idx].intlDes}`] = idx;
}
}
return tempSatData;
}
private static processExtraSats_(extraSats: ExtraSat[], catalogManagerInstance: CatalogManager, tempSatData: any[]) {
// If extra catalogue
for (const element of extraSats) {
if (!element.SCC || !element.TLE1 || !element.TLE2) {
continue;
} // Don't Process Bad Satellite Information
if (typeof catalogManagerInstance.sccIndex[`${element.SCC}`] !== 'undefined') {
const i = catalogManagerInstance.sccIndex[`${element.SCC}`];
if (typeof tempSatData[i] === 'undefined') {
continue;
}
tempSatData[i].TLE1 = element.TLE1;
tempSatData[i].TLE2 = element.TLE2;
tempSatData[i].source = CatalogSource.EXTRA_JSON;
} else {
const intlDes = CatalogLoader.parseIntlDes_(element.TLE1);
const extrasSatInfo = {
static: false,
missile: false,
active: true,
name: element.ON || 'Unknown',
type: element.OT || SpaceObjectType.SPECIAL,
country: 'Unknown',
rocket: 'Unknown',
site: 'Unknown',
sccNum: element.SCC.toString(),
tle1: element.TLE1 as TleLine1,
tle2: element.TLE2 as TleLine2,
source: 'extra.json',
intlDes,
typ: 'sat', // TODO: What is this?
id: tempSatData.length,
vmag: element.vmag,
};
catalogManagerInstance.sccIndex[`${element.SCC.toString()}`] = tempSatData.length;
catalogManagerInstance.cosparIndex[`${intlDes}`] = tempSatData.length;
const satellite = new DetailedSatellite({
tle1: extrasSatInfo.tle1,
tle2: extrasSatInfo.tle2,
...extrasSatInfo,
});
satellite.id = tempSatData.length;
tempSatData.push(satellite);
}
}
}
private static processJsCatalog_(jsCatalog: JsSat[], catalogManagerInstance: CatalogManager, tempObjData: any[]) {
errorManagerInstance.debug(`Processing ${settingsManager.isEnableJscCatalog ? 'JSC Vimpel' : 'Extended'} Catalog`);
// If jsCatalog catalogue
for (const element of jsCatalog) {
if (!element.TLE1 || !element.TLE2) {
continue;
} // Don't Process Bad Satellite Information
const scc = Tle.convertA5to6Digit(element.TLE1.substring(2, 7).trim());
if (typeof catalogManagerInstance.sccIndex[`${scc}`] !== 'undefined') {
/*
* console.warn('Duplicate Satellite Found in jsCatalog');
* NOTE: We don't trust the jsCatalog, so we don't update the TLEs
* i = catalogManagerInstance.sccIndex[`${jsCatalog[s].SCC}`];
* tempSatData[i].TLE1 = jsCatalog[s].TLE1;
* tempSatData[i].TLE2 = jsCatalog[s].TLE2;
*/
} else {
// Check if the 8th character is 'V' for Vimpel
const isVimpel = element.TLE1[7] === 'V';
if (isVimpel) {
const altId = element.TLE1.substring(9, 17).trim();
const jsSatInfo = {
static: false,
missile: false,
active: true,
name: `JSC Vimpel ${altId}`,
type: SpaceObjectType.DEBRIS,
country: 'Unknown',
rocket: 'Unknown',
site: 'Unknown',
sccNum: '',
TLE1: element.TLE1,
TLE2: element.TLE2,
source: 'JSC Vimpel',
altId,
intlDes: '',
id: tempObjData.length,
};
const satellite = new DetailedSatellite({
tle1: jsSatInfo.TLE1 as TleLine1,
tle2: jsSatInfo.TLE2 as TleLine2,
...jsSatInfo,
});