-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4906b9
commit e712cd1
Showing
49 changed files
with
5,635 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// swift-tools-version: 5.6 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "SGPKit", | ||
platforms: [.iOS(.v13)], | ||
products: [ | ||
.library( | ||
name: "SGPKit", | ||
targets: ["SGPKit"]), | ||
], | ||
dependencies: [ | ||
|
||
], | ||
targets: [ | ||
.target( | ||
name: "SGPKit", | ||
dependencies: ["SGPKitOBJC"]), | ||
.target( | ||
name: "SGPKitCPP", | ||
path: "Sources/sgp4-f5cb54b" | ||
), | ||
.target( | ||
name: "SGPKitOBJC", | ||
dependencies: ["SGPKitCPP"], | ||
path: "Sources/OBJC"), | ||
.testTarget( | ||
name: "SGPKitTests", | ||
dependencies: ["SGPKit"]), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,41 @@ | ||
# swift-spg | ||
A Swift package to compute satellite positions from two-line elements (TLE). | ||
A Swift package to compute satellite positions from two-line elements (TLE), wrapping the [sgp4lib](https://www.danrw.com/sgp4/) library (by Daniel Warner) | ||
|
||
|
||
## Usage | ||
|
||
```swift | ||
import SGPKit | ||
|
||
let firstLine = "1 25544U 98067A 13165.59097222 .00004759 00000-0 88814-4 0 47" | ||
let secondLine = "2 25544 51.6478 121.2152 0011003 68.5125 263.9959 15.50783143834295" | ||
|
||
// Instantiate a new TLE descriptor | ||
let tle = TLE(firstLine: firstLine, secondLine: secondLine) | ||
|
||
// Instantiate the interpreter | ||
let interpreter = TLEInterpreter() | ||
|
||
// Obtain the data | ||
let data: SatelliteData = interpreter.satelliteData(from: tle, date: .now) | ||
|
||
print(data.latitude) | ||
print(data.longitude) | ||
print(data.altitude) | ||
print(data.speed) | ||
``` | ||
|
||
## Installation | ||
|
||
### Swift Package Manager | ||
|
||
If you want to use SGPKit in any other project that uses [SwiftPM](https://swift.org/package-manager/), add the package as a dependency in `Package.swift`: | ||
|
||
```swift | ||
dependencies: [ | ||
.package( | ||
url: "https://github.com/csanfilippo/swift-sgp", | ||
from: "1.0.0" | ||
), | ||
] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
MIT License | ||
Copyright (c) 2022 Calogero Sanfilippo | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
|
||
#import "SGP4Wrapper.h" | ||
#import <Foundation/Foundation.h> | ||
#import <iostream> | ||
#import <SGP4.h> | ||
#import <Tle.h> | ||
#import <DateTime.h> | ||
#import <CoordGeodetic.h> | ||
#import <Eci.h> | ||
using namespace std; | ||
|
||
@implementation SGP4Wrapper | ||
|
||
- (SatelliteData* _Nonnull) getSatelliteDataFrom:(TLEWrapper*) tleWrapper date:(NSDate*) date { | ||
SGP4 (^getSGP4)(void) = ^{ | ||
|
||
string first("ISS (ZARYA)"); | ||
string second(tleWrapper.firstLine.UTF8String); | ||
string third(tleWrapper.secondLine.UTF8String); | ||
|
||
Tle tle(first, second, third); | ||
SGP4 sgp4(tle); | ||
return sgp4; | ||
}; | ||
|
||
SGP4 sgp4 = getSGP4(); | ||
|
||
DateTime currentTime = [self dateTimeFrom: date]; | ||
|
||
SatelliteData *data = [self issDataFromSgp4:sgp4 Date:currentTime]; | ||
|
||
return data; | ||
} | ||
|
||
- (DateTime) dateTimeFrom:(NSDate*) date { | ||
|
||
NSCalendar *calendar = [NSCalendar currentCalendar]; | ||
calendar.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0]; | ||
|
||
int day = static_cast<int>([calendar component:NSCalendarUnitDay fromDate:date]); | ||
int month = static_cast<int>([calendar component:NSCalendarUnitMonth fromDate:date]); | ||
int year = static_cast<int>([calendar component:NSCalendarUnitYear fromDate:date]); | ||
int hour = static_cast<int>([calendar component:NSCalendarUnitHour fromDate:date]); | ||
int minute = static_cast<int>([calendar component:NSCalendarUnitMinute fromDate:date]); | ||
int second = static_cast<int>([calendar component:NSCalendarUnitSecond fromDate:date]); | ||
int micro = static_cast<int>([calendar component:NSCalendarUnitNanosecond fromDate:date] / 1000); | ||
|
||
DateTime time = DateTime(year, month, day, hour, minute, second); | ||
time.Initialise(year, month, day, hour, minute, second, micro); | ||
return time; | ||
} | ||
|
||
- (SatelliteData *) issDataFromSgp4:(SGP4) sgp4 Date:(DateTime) date { | ||
Eci eci = sgp4.FindPosition(date); | ||
CoordGeodetic geo = eci.ToGeodetic(); | ||
|
||
double velocity = eci.Velocity().Magnitude() * 3600.0; | ||
return [[SatelliteData alloc] initWithLatitude:geo.latitude * 180.0 / M_PI longitude:geo.longitude * 180.0 / M_PI speed:velocity altitude:geo.altitude]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
MIT License | ||
Copyright (c) 2022 Calogero Sanfilippo | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
|
||
#import "SatelliteData.h" | ||
|
||
@interface SatelliteData () | ||
@property(readwrite) double latitude; | ||
@property(readwrite) double longitude; | ||
@property(readwrite) double speed; | ||
@property(readwrite) double altitude; | ||
@end | ||
|
||
@implementation SatelliteData | ||
- (instancetype) initWithLatitude:(double) latitude longitude:(double) longitude speed:(double) speed altitude:(double) altitude { | ||
self = [super init]; | ||
if (self) { | ||
self.latitude = latitude; | ||
self.longitude = longitude; | ||
self.speed = speed; | ||
self.altitude = altitude; | ||
} | ||
return self; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
MIT License | ||
Copyright (c) 2022 Calogero Sanfilippo | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
|
||
#import "TLEWrapper.h" | ||
|
||
@implementation TLEWrapper | ||
|
||
- (instancetype)initWithFirstLine:(NSString *)firstLine secondLine:(NSString *)secondLine { | ||
self = [super init]; | ||
|
||
if (self) { | ||
self.firstLine = firstLine; | ||
self.secondLine = secondLine; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
MIT License | ||
Copyright (c) 2022 Calogero Sanfilippo | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "SatelliteData.h" | ||
#import "TLEWrapper.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface SGP4Wrapper : NSObject | ||
|
||
- (SatelliteData* _Nonnull) getSatelliteDataFrom:(TLEWrapper* _Nonnull) tle date:(NSDate* _Nonnull) date; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
MIT License | ||
Copyright (c) 2022 Calogero Sanfilippo | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface SatelliteData : NSObject | ||
@property(readonly) double latitude; | ||
@property(readonly) double longitude; | ||
@property(readonly) double speed; | ||
@property(readonly) double altitude; | ||
|
||
- (instancetype) initWithLatitude:(double) latitude longitude:(double) longitude speed:(double) speed altitude:(double) altitude; | ||
|
||
@end |
Oops, something went wrong.