-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.hh
90 lines (79 loc) · 2.81 KB
/
main.hh
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
// satnow: main.hh
//
// Copyright 2019 Matt Davis (https://github.com/enferex)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __SATNOW_MAIN_HH
#define __SATNOW_MAIN_HH
#include "db.hh"
#include <CoordTopocentric.h>
#include <DateTime.h>
#include <Observer.h>
#include <SGP4.h>
#include <algorithm>
// Version info. Excuse the ugly trick to get strigification for a macro value.
#define MAJOR 0
#define MINOR 1
#define PATCH 0
#define _VER2(_x, _y, _z) #_x "." #_y "." #_z
#define _VER(_x, _y, _z) _VER2(_x, _y, _z)
#define VER _VER(MAJOR, MINOR, PATCH)
// TLE and look angle pair.
using SatLookAngle = std::pair<Tle, CoordTopocentric>;
// Container class for holding Tle and look angles.
class SatLookAngles {
private:
double _lat, _lon, _alt;
std::vector<SatLookAngle> _sats;
Observer _me;
DateTime _time;
public:
SatLookAngles(double lat, double lon, double alt)
: _me(lat, lon, alt), _time(DateTime::Now(true)) {}
// Add the tle to the _sats container, and also
// generate the look angle at _time.
void add(Tle tle) {
const auto model = SGP4(tle);
const auto pos = model.FindPosition(_time);
const auto la = _me.GetLookAngle(pos);
_sats.emplace_back(tle, la);
}
// Regenerate new look angles with the current time.
void updateTimeAndPositions() {
_time = DateTime::Now(true);
for (auto &sat : _sats) {
const auto model = SGP4(sat.first);
const auto pos = model.FindPosition(_time);
sat.second = _me.GetLookAngle(pos);
}
}
// Sort the satellites based on range (closest to furthest).
void sort() {
std::sort(_sats.begin(), _sats.end(),
[](const SatLookAngle &a, const SatLookAngle &b) {
return a.second.range < b.second.range;
});
}
std::vector<SatLookAngle>::iterator begin() { return _sats.begin(); }
std::vector<SatLookAngle>::iterator end() { return _sats.end(); }
size_t size() const { return _sats.size(); }
SatLookAngle &operator[](size_t index) {
assert(index < size() && "Invalid index.");
return _sats[index];
}
};
// Queries the DB for TLE entries, and generates a container of TLEs and their
// look angles with respect to lat/lon/alt.
SatLookAngles getSatellitesAndLookAngles(double lat, double lon, double alt,
DB &db);
#endif // __SATNOW_MAIN_HH