libdrmconf 0.14.1
A library to program DMR radios.
Loading...
Searching...
No Matches
orbitalelementsdatabase.hh
1
3
4#ifndef ORBITALELEMENTSDATABASE_HH
5#define ORBITALELEMENTSDATABASE_HH
6
7#include <QAbstractTableModel>
8#include <QNetworkAccessManager>
9
10
15{
16public:
18 struct Epoch {
20 unsigned int year;
22 unsigned int month;
24 unsigned int day;
26 unsigned int hour;
28 unsigned int minute;
30 unsigned int second;
32 unsigned int microsecond;
33
35 Epoch();
37 Epoch(unsigned int year, unsigned int month, unsigned int day,
38 unsigned int hour, unsigned int minute, unsigned int second, unsigned int microsecond);
40 Epoch(const Epoch &other) = default;
42 Epoch &operator =(const Epoch &other) = default;
43
45 static Epoch parse(const QString &datetime);
47 double toEpoch() const;
49 QString toString() const;
50 };
51
52public:
56 OrbitalElement(unsigned int id);
58 OrbitalElement(const OrbitalElement &other) = default;
60 OrbitalElement &operator=(const OrbitalElement &other) = default;
61
63 bool isValid() const;
65 unsigned int id() const;
67 const QString &name() const;
68
70 const Epoch &epoch() const;
72 double meanMotion() const;
74 double meanMotionDerivative() const;
76 double inclination() const;
78 double ascension() const;
80 double eccentricity() const;
82 double perigee() const;
84 double meanAnomaly() const;
86 unsigned int revolutionNumber() const;
87
88public:
90 static OrbitalElement fromCelesTrak(const QJsonObject &obj);
91
92protected:
94 unsigned int _id;
96 QString _name;
110 double _perigee;
114 unsigned int _revolutionNumber;
115};
116
117
118
121class OrbitalElementsDatabase: public QAbstractTableModel
122{
123 Q_OBJECT
124
125public:
130 explicit OrbitalElementsDatabase(bool autoLoad, unsigned int updatePeriodDays=7, QObject *parent=nullptr);
131
133 bool contains(unsigned int id) const;
135 OrbitalElement getById(unsigned int id) const;
137 const OrbitalElement &getAt(unsigned int idx) const;
139 OrbitalElement &getAt(unsigned int idx);
140
142 unsigned int dbAge() const;
144 void load();
145
147 int rowCount(const QModelIndex &parent = QModelIndex()) const;
149 int columnCount(const QModelIndex &parent = QModelIndex()) const;
151 QVariant data(const QModelIndex &index, int role) const;
153 QVariant headerData(int section, Qt::Orientation orientation, int role) const;
154
155signals:
157 void loaded();
159 void error(const QString &msg);
160
161public slots:
163 void download();
164
165private slots:
167 void downloadFinished(QNetworkReply *reply);
168
169protected:
171 bool load(const QString &filename);
172
173private:
175 unsigned int _updatePeriod;
177 QVector<OrbitalElement> _elements;
179 QHash<unsigned int, unsigned int> _idIndexMap;
181 QNetworkAccessManager _network;
182};
183
184#endif // ORBITALELEMENTSDATABASE_HH
Defines a single orbital element, enabling the tracking of a single satellite.
Definition orbitalelementsdatabase.hh:15
Epoch _epoch
The epoch.
Definition orbitalelementsdatabase.hh:98
double _eccentricity
Eccentricity.
Definition orbitalelementsdatabase.hh:108
double _perigee
Argument of perigee.
Definition orbitalelementsdatabase.hh:110
const Epoch & epoch() const
Epoch of the orbital elements.
Definition orbitalelementsdatabase.cc:110
const QString & name() const
Returns the name of the satellite.
Definition orbitalelementsdatabase.cc:105
double _meanAnomaly
Mean anomaly.
Definition orbitalelementsdatabase.hh:112
unsigned int revolutionNumber() const
Returns the revolution number.
Definition orbitalelementsdatabase.cc:150
double _ascension
Right ascension of the ascending node.
Definition orbitalelementsdatabase.hh:106
double meanMotionDerivative() const
Returns the first derivative of the mean motion.
Definition orbitalelementsdatabase.cc:120
double eccentricity() const
Returns the eccentricity.
Definition orbitalelementsdatabase.cc:135
double _meanMotion
Mean motion.
Definition orbitalelementsdatabase.hh:100
unsigned int id() const
Returns the NORAD catalog id.
Definition orbitalelementsdatabase.cc:100
double ascension() const
Returns the right ascension of the ascending node.
Definition orbitalelementsdatabase.cc:130
unsigned int _revolutionNumber
The revolution number.
Definition orbitalelementsdatabase.hh:114
unsigned int _id
NORAD id of the satellite.
Definition orbitalelementsdatabase.hh:94
OrbitalElement(const OrbitalElement &other)=default
Copy constructor.
static OrbitalElement fromCelesTrak(const QJsonObject &obj)
Constructs a orbital element from a CelesTrak JSON object.
Definition orbitalelementsdatabase.cc:156
double meanMotion() const
Returns the mean motion.
Definition orbitalelementsdatabase.cc:115
double meanAnomaly() const
Returns the mean anomaly.
Definition orbitalelementsdatabase.cc:145
OrbitalElement()
Default constructor.
Definition orbitalelementsdatabase.cc:77
double inclination() const
Returns the inclination.
Definition orbitalelementsdatabase.cc:125
QString _name
Descriptive name of the satellite.
Definition orbitalelementsdatabase.hh:96
bool isValid() const
Returns true, if this represents a valid satellite information.
Definition orbitalelementsdatabase.cc:95
double _inclination
Inclination.
Definition orbitalelementsdatabase.hh:104
OrbitalElement & operator=(const OrbitalElement &other)=default
Copy assignment.
double _meanMotionDerivative
First derivative of the mean motion.
Definition orbitalelementsdatabase.hh:102
double perigee() const
Returns the argument of perigee.
Definition orbitalelementsdatabase.cc:140
OrbitalElementsDatabase(bool autoLoad, unsigned int updatePeriodDays=7, QObject *parent=nullptr)
Constructs a orbital element database.
Definition orbitalelementsdatabase.cc:180
QVariant headerData(int section, Qt::Orientation orientation, int role) const
Returns a single header of the database table.
Definition orbitalelementsdatabase.cc:241
void load()
If needed, downloads the database and loads all received orbital elements.
Definition orbitalelementsdatabase.cc:266
OrbitalElement getById(unsigned int id) const
Returns the orbital elements for the satellite with the given NORAD id.
Definition orbitalelementsdatabase.cc:196
unsigned int dbAge() const
Returns the current age of the cache.
Definition orbitalelementsdatabase.cc:256
void loaded()
Gets emitted once the satellite orbitals has been loaded.
const OrbitalElement & getAt(unsigned int idx) const
Returns the i-th orbital element.
Definition orbitalelementsdatabase.cc:201
QVariant data(const QModelIndex &index, int role) const
Returns a single cell of the database table.
Definition orbitalelementsdatabase.cc:224
bool contains(unsigned int id) const
returns true if the database contains a satellite with the given NORAD id.
Definition orbitalelementsdatabase.cc:191
int columnCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of columns of the database table.
Definition orbitalelementsdatabase.cc:218
int rowCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of elements in the database.
Definition orbitalelementsdatabase.cc:212
void error(const QString &msg)
Gets emitted if the loading one of the sources fails.
void download()
Starts the download of the orbital elements.
Definition orbitalelementsdatabase.cc:332
Represents a Julien day epoch since a specified year.
Definition orbitalelementsdatabase.hh:18
unsigned int second
The second.
Definition orbitalelementsdatabase.hh:30
unsigned int year
The year of the epoch.
Definition orbitalelementsdatabase.hh:20
double toEpoch() const
Computes the decimal epoch as the day of year a.
Definition orbitalelementsdatabase.cc:50
unsigned int microsecond
The microsecond.
Definition orbitalelementsdatabase.hh:32
QString toString() const
Encodes the Epoch as YYYY-MM-DDThh:mm:ss.uuuuuu.
Definition orbitalelementsdatabase.cc:61
unsigned int hour
The hour.
Definition orbitalelementsdatabase.hh:26
Epoch()
Default constructor.
Definition orbitalelementsdatabase.cc:16
unsigned int month
The month.
Definition orbitalelementsdatabase.hh:22
static Epoch parse(const QString &datetime)
Parses a date-time string into the epoch.
Definition orbitalelementsdatabase.cc:33
unsigned int minute
The minute.
Definition orbitalelementsdatabase.hh:28
unsigned int day
The day.
Definition orbitalelementsdatabase.hh:24
Epoch & operator=(const Epoch &other)=default
Copy assignment.
Epoch(const Epoch &other)=default
Copy constructor.