1
1
/*
2
+ * Stellarium
2
3
* Copyright (C) 2023 Andy Kirkham
3
4
*
4
5
* This program is free software; you can redistribute it and/or
23
24
24
25
#include " OMM.hpp"
25
26
26
- namespace PluginSatellites {
27
-
28
27
OMM::OMM ()
29
28
{
30
29
m_source_type = SourceType::Invalid;
@@ -44,7 +43,8 @@ OMM::OMM(QString & l1, QString & l2)
44
43
m_source_type = SourceType::LegacyTle;
45
44
m_line1 = l1;
46
45
m_line2 = l2;
47
- processTleLegacy ();
46
+ processTleLegacyLine1 ();
47
+ processTleLegacyLine2 ();
48
48
}
49
49
50
50
OMM::OMM (QString& l0, QString& l1, QString& l2)
@@ -53,7 +53,9 @@ OMM::OMM(QString& l0, QString& l1, QString& l2)
53
53
m_line0 = l0;
54
54
m_line1 = l1;
55
55
m_line2 = l2;
56
- processTleLegacy ();
56
+ processTleLegacyLine0 ();
57
+ processTleLegacyLine1 ();
58
+ processTleLegacyLine2 ();
57
59
}
58
60
59
61
bool OMM::hasValidLegacyTleData ()
@@ -108,10 +110,7 @@ bool OMM::setFromXML(QXmlStreamReader & r)
108
110
109
111
void OMM::processXmlElement (const QString & tag, const QString & val)
110
112
{
111
- if (tag == " EPOCH" ) {
112
- m_epoch_str = val;
113
- m_epoch = QDateTime::fromString (val, " yyyy-MM-ddThh:mm:ss.zzzzzz" );
114
- }
113
+ if (tag == " EPOCH" ) m_sp_epoch = OMMDateTime::ShPtr (new OMMDateTime (val, OMMDateTime::STR_ISO8601));
115
114
else if (tag == " OBJECT_NAME" ) m_object_name = val;
116
115
else if (tag == " OBJECT_ID" ) m_object_id = val;
117
116
else if (tag == " MEAN_MOTION" ) m_mean_motion = val.toDouble ();
@@ -122,27 +121,56 @@ void OMM::processXmlElement(const QString & tag, const QString & val)
122
121
else if (tag == " MEAN_ANOMALY" ) m_mean_anomoly = val.toDouble ();
123
122
else if (tag == " CLASSIFICATION_TYPE" ) m_classification = val.at (0 ).toUpper ();
124
123
else if (tag == " NORAD_CAT_ID" ) m_norad_cat_id = val.toInt ();
125
- else if (tag == " ELEMENT_SET_NO" ) m_element_set_no = val.toInt ();
124
+ else if (tag == " ELEMENT_SET_NO" ) m_element_number = val.toInt ();
126
125
else if (tag == " REV_AT_EPOCH" ) m_rev_at_epoch = val.toInt ();
127
126
else if (tag == " BSTAR" ) m_bstar = val.toDouble ();
128
127
else if (tag == " MEAN_MOTION_DOT" ) m_mean_motion_dot = val.toDouble ();
129
128
else if (tag == " MEAN_MOTION_DDOT" ) m_mean_motion_ddot = val.toDouble ();
130
129
}
131
130
132
- // Everything below here is for extracting the data from the two TLE lines .
131
+ // Everything below here is for extracting the data from the legacy two line TLE format .
133
132
134
- // J F M A M J J A S O N D
135
- static int month_lens[] = { 0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
133
+ void OMM::processTleLegacyLine0 (void )
134
+ {
135
+ if (!m_line0.isEmpty ()) {
136
+ m_object_name = m_line0.trimmed ();
137
+ }
138
+ }
136
139
137
140
// TLE Line1 field positions and lengths.
138
141
static QPair<int , int > NORAD_CAT_ID (2 ,5 );
139
142
static QPair<int , int > CLASSIFICATION_TYPE (7 ,1 );
140
143
static QPair<int , int > OBJECT_ID (9 , 8 );
144
+ static QPair<int , int > EPOCH (18 , 14 );
141
145
static QPair<int , int > EPOCH_YEAR (18 , 2 );
142
146
static QPair<int , int > EPOCH_DAY (20 , 12 );
143
147
static QPair<int , int > MEAN_MOTION_DOT (33 , 10 );
144
148
static QPair<int , int > MEAN_MOTION_DDOT (44 , 8 );
145
149
static QPair<int , int > BSTAR (53 , 8 );
150
+ static QPair<int , int > EPHEMERIS_TYPE (62 , 1 );
151
+ static QPair<int , int > ELEMENT_NUMBER (64 , 4 );
152
+
153
+ void OMM::processTleLegacyLine1 (void )
154
+ {
155
+ if (!m_line1.isEmpty () && m_line1.at (0 ) == ' 1' ) {
156
+ auto epoch_str = m_line1.mid (EPOCH.first , EPOCH.second ).trimmed ();
157
+ m_sp_epoch = OMMDateTime::ShPtr (new OMMDateTime (epoch_str));
158
+ m_norad_cat_id = m_line1.mid (NORAD_CAT_ID.first , NORAD_CAT_ID.second ).toInt ();
159
+ m_classification = m_line1.at (CLASSIFICATION_TYPE.first );
160
+ m_object_id = m_line1.mid (OBJECT_ID.first , OBJECT_ID.second ).trimmed ();
161
+ m_mean_motion_dot = m_line1.mid (33 , 10 ).toDouble ();
162
+ QString ddot (" ." );
163
+ ddot.append (m_line1.mid (44 , 5 ));
164
+ ddot.replace (QChar (' -' ), QString (" e-" ));
165
+ m_mean_motion_ddot = ddot.toDouble ();
166
+ QString bstar (" ." );
167
+ bstar.append (m_line1.mid (BSTAR.first , BSTAR.second ).trimmed ());
168
+ bstar.replace (QChar (' -' ), QString (" e-" ));
169
+ m_bstar = bstar.toDouble ();
170
+ m_ephermeris_type = m_line1.mid (EPHEMERIS_TYPE.first , EPHEMERIS_TYPE.second ).trimmed ().toInt ();
171
+ m_element_number = m_line1.mid (ELEMENT_NUMBER.first , ELEMENT_NUMBER.second ).trimmed ().toInt ();
172
+ }
173
+ }
146
174
147
175
// TLE Line2 field positions and lengths.
148
176
static QPair<int , int > INCLINATION (8 , 8 );
@@ -153,25 +181,18 @@ static QPair<int, int> MEAN_ANOMALY(43, 8);
153
181
static QPair<int , int > MEAN_MOTION (52 , 11 );
154
182
static QPair<int , int > REV_AT_EPOCH (63 , 5 );
155
183
156
- void OMM::processTleLegacy (void )
184
+ void OMM::processTleLegacyLine2 (void )
157
185
{
158
- if (m_line1.at (0 ) == ' 1' ) {
159
- m_norad_cat_id = m_line1.mid (NORAD_CAT_ID.first , NORAD_CAT_ID.second ).toInt ();
160
- m_classification = m_line1.at (CLASSIFICATION_TYPE.first );
161
- m_object_id = m_line1.mid (OBJECT_ID.first , OBJECT_ID.second ).trimmed ();
162
- int epoch_year = m_line1.mid (EPOCH_YEAR.first , EPOCH_YEAR.second ).toInt ();
163
- if (epoch_year < 57 ) epoch_year += 2000 ;
164
- else epoch_year += 1900 ;
165
- QDate year = QDate (epoch_year, 1 , 1 );
166
- double epoch_day = m_line1.mid (EPOCH_DAY.first , EPOCH_DAY.second ).toDouble ();
167
- int day = std::floor (epoch_day);
168
-
169
- // 18-31 Epoch. Element Set Epoch (UTC) *Note: spaces are acceptable in columns 20 & 21
170
- m_mean_motion_dot = m_line1.mid (33 , 10 ).toDouble ();
171
- QString dec (" ." );
172
- dec.append (m_line1.mid (44 , 5 ));
173
- m_mean_motion_ddot = dec.toDouble ();
186
+ if (!m_line2.isEmpty () && m_line2.at (0 ) == ' 2' ) {
187
+ m_inclination = m_line2.mid (INCLINATION.first , INCLINATION.second ).trimmed ().toDouble ();
188
+ m_ascending_node = m_line2.mid (RA_OF_ASC_NODE.first , RA_OF_ASC_NODE.second ).trimmed ().toDouble ();
189
+ m_argument_perigee = m_line2.mid (ARG_OF_PERICENTER.first , ARG_OF_PERICENTER.second ).trimmed ().toDouble ();
190
+ QString ecc_s (" ." );
191
+ ecc_s.append (m_line2.mid (ECCENTRICITY.first , ECCENTRICITY.second ));
192
+ m_eccentricity = ecc_s.trimmed ().toDouble ();
193
+ m_mean_anomoly = m_line2.mid (MEAN_ANOMALY.first , MEAN_ANOMALY.second ).trimmed ().toDouble ();
194
+ m_mean_motion = m_line2.mid (MEAN_MOTION.first , MEAN_MOTION.second ).trimmed ().toDouble ();
195
+ m_rev_at_epoch = m_line2.mid (REV_AT_EPOCH.first , REV_AT_EPOCH.second ).trimmed ().toInt ();
196
+
174
197
}
175
198
}
176
-
177
- } // end namespace PluginSatellites
0 commit comments