diff --git a/src/objects/Satellite.ts b/src/objects/Satellite.ts index f7664a1..e1e5abc 100644 --- a/src/objects/Satellite.ts +++ b/src/objects/Satellite.ts @@ -61,45 +61,53 @@ import { TimeVariables } from '../interfaces/TimeVariables'; * calculating its position and other properties. */ export class Satellite extends BaseObject { - apogee: Kilometers; - argOfPerigee: Degrees; - bstar: number; - eccentricity: number; - epochDay: number; - epochYear: number; - inclination: Degrees; - intlDes: string; - meanAnomaly: Degrees; - meanMoDev1: number; - meanMoDev2: number; - meanMotion: number; + apogee!: Kilometers; + argOfPerigee!: Degrees; + bstar!: number; + eccentricity!: number; + epochDay!: number; + epochYear!: number; + inclination!: Degrees; + intlDes!: string; + meanAnomaly!: Degrees; + meanMoDev1!: number; + meanMoDev2!: number; + meanMotion!: number; options: OptionsParams; - perigee: Kilometers; - period: Minutes; - rightAscension: Degrees; - satrec: SatelliteRecord; + perigee!: Kilometers; + period!: Minutes; + rightAscension!: Degrees; + satrec!: SatelliteRecord; /** The satellite catalog number as listed in the TLE. */ - sccNum: string; + sccNum!: string; /** The 5 digit alpha-numeric satellite catalog number. */ - sccNum5: string; + sccNum5!: string; /** The 6 digit numeric satellite catalog number. */ - sccNum6: string; - tle1: TleLine1; - tle2: TleLine2; + sccNum6!: string; + tle1!: TleLine1; + tle2!: TleLine2; /** The semi-major axis of the satellite's orbit. */ - semiMajorAxis: Kilometers; + semiMajorAxis!: Kilometers; /** The semi-minor axis of the satellite's orbit. */ - semiMinorAxis: Kilometers; + semiMinorAxis!: Kilometers; constructor(info: SatelliteParams, options?: OptionsParams) { super(info); - const tleData = Tle.parse(info.tle1, info.tle2); + this.parseTleAndUpdateOrbit_(info.tle1, info.tle2, info.sccNum); - this.tle1 = info.tle1; - this.tle2 = info.tle2; + this.options = options ?? { + notes: '', + }; + } - this.sccNum = info.sccNum ?? tleData.satNum.toString(); + private parseTleAndUpdateOrbit_(tle1: TleLine1, tle2: TleLine2, sccNum?: string) { + const tleData = Tle.parse(tle1, tle2); + + this.tle1 = tle1; + this.tle2 = tle2; + + this.sccNum = sccNum ?? tleData.satNum.toString(); this.sccNum5 = Tle.convert6DigitToA5(this.sccNum); this.sccNum6 = Tle.convertA5to6Digit(this.sccNum5); this.intlDes = tleData.intlDes; @@ -119,13 +127,7 @@ export class Satellite extends BaseObject { this.semiMinorAxis = (this.semiMajorAxis * Math.sqrt(1 - this.eccentricity ** 2)) as Kilometers; this.apogee = (this.semiMajorAxis * (1 + this.eccentricity) - 6371) as Kilometers; this.perigee = (this.semiMajorAxis * (1 - this.eccentricity) - 6371) as Kilometers; - - // NOTE: Calculate apogee and perigee - - this.satrec = Sgp4.createSatrec(info.tle1, info.tle2); - this.options = options ?? { - notes: '', - }; + this.satrec = Sgp4.createSatrec(tle1, tle2); } /** @@ -165,6 +167,10 @@ export class Satellite extends BaseObject { return true; } + editTle(tle1: TleLine1, tle2: TleLine2, sccNum?: string): void { + this.parseTleAndUpdateOrbit_(tle1, tle2, sccNum); + } + /** * Calculates the azimuth angle of the satellite relative to the given sensor at the specified date. If no date is * provided, the current time of the satellite is used.