COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
check_satnogs.cpp File Reference
Include dependency graph for check_satnogs.cpp:

Functions

int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)
38 {
39  int32_t iretn = 0;
40  vector<tlestruc> tles;
41 
42  iretn = load_lines(argv[1], tles);
43 
44  string input;
45  double tovernal;
46 
47  if (argc == 3)
48  {
49  if (data_isfile(argv[2]))
50  {
51  FILE *fp = fopen(argv[2], "r");
52  int ic;
53  while ((ic=fgetc(fp)) != EOF)
54  {
55  input.push_back(ic);
56  };
57 
58  Json jobject;
59  jobject.extract_contents(input);
60 
61  locstruc currentloc;
62  lines2eci(currentmjd(), tles, currentloc.pos.eci);
63  currentloc.pos.eci.pass++;
64  pos_eci(currentloc);
65  kepstruc currentkep;
66  eci2kep(currentloc.pos.eci, currentkep);
67  tovernal = atan2(currentloc.pos.extra.sun2earth.s.col[1], currentloc.pos.extra.sun2earth.s.col[0]);
68 
69  for (const auto& member : jobject.ArrayContents)
70  {
71  double start = iso86012utc(member.object.at("start").svalue);
72  locstruc startloc;
73  lines2eci(start, tles, startloc.pos.eci);
74  startloc.pos.eci.pass++;
75  pos_eci(startloc);
76  kepstruc startkep;
77  eci2kep(startloc.pos.eci, startkep);
78  tovernal = atan2(startloc.pos.extra.sun2earth.s.col[1], startloc.pos.extra.sun2earth.s.col[0]);
79  double startphase = fixangle(startkep.ma + startkep.raan - tovernal);
80 
81  double end = iso86012utc(member.object.at("end").svalue);
82  locstruc endloc;
83  lines2eci(end, tles, endloc.pos.eci);
84  endloc.pos.eci.pass++;
85  pos_eci(endloc);
86  kepstruc endkep;
87  eci2kep(endloc.pos.eci, endkep);
88  tovernal = atan2(endloc.pos.extra.sun2earth.s.col[1], endloc.pos.extra.sun2earth.s.col[0]);
89  double endphase = fixangle(endkep.ma + endkep.raan - tovernal);
90  // double endphase = (endloc.pos.earthsep) / cos(endkep.beta);
91 
92  double dphase = (1./86400.) * (endphase - startphase) / (end - start);
93 
94  printf("%s\t", member.object.at("id").svalue.c_str());
95  printf("%s\t", member.object.at("start").svalue.c_str());
96  printf("%s\t", to_mjd(start).c_str());
97  printf("%s\t", to_double(DEGOF(startloc.pos.earthsep)).c_str());
98  printf("%s\t", to_double(DEGOF(startphase)).c_str());
99 
100  printf("%s\t", member.object.at("end").svalue.c_str());
101  printf("%s\t", to_mjd(end).c_str());
102  printf("%s\t", to_double(DEGOF(endloc.pos.earthsep)).c_str());
103  printf("%s\t", to_double(DEGOF(endphase)).c_str());
104 
105  printf("%s\t", to_double(DEGOF(dphase), 5).c_str());
106 
107  if (member.object.at("status").svalue == "good")
108  {
109  printf("1");
110  }
111  else {
112  printf("0");
113  }
114 
115  printf("\n");
116  }
117  }
118  else {
119  float minelev = RADOF(15.);
120  string nodename = argv[2];
121  if (nodename.find(":") != string::npos)
122  {
123  minelev = RADOF(stof(nodename.substr(nodename.find(":")+1)));
124  nodename = nodename.substr(0, nodename.find(":"));
125  }
126  Agent *agent = new Agent(nodename);
127  if ((iretn = agent->wait()) >= 0)
128  {
129  double utcnow;
131  targetstruc aos;
132  targetstruc tca;
133  targetstruc los;
134  //double startutc;
135  bool visible = false;
136  bool peaked = false;
137  float highest = -RADOF(90.);
138  for (utcnow=59159.642; utcnow<currentmjd(); utcnow+=1./86400)
139  {
140  lines2eci(utcnow, tles, target.loc.pos.eci);
141  target.loc.pos.eci.pass++;
142  pos_eci(target.loc);
143  update_target(agent->cinfo->node.loc, target);
144  switch (static_cast<uint8_t>(visible))
145  {
146  case 0:
147  if (target.elfrom > 0.f)
148  {
149  aos = target;
150  highest = 0.;
151  //startutc = utcnow;
152  visible = true;
153  peaked = false;
154  }
155  break;
156  case 1:
157  if (target.elfrom > highest)
158  {
159  highest = target.elfrom;
160  }
161  else if (!peaked)
162  {
163  peaked = true;
164  tca = target;
165  }
166  if (target.elfrom < 0.f)
167  {
168  los = target;
169  visible = false;
170  if (tca.elfrom >= minelev)
171  {
172  kepstruc startkep;
173  eci2kep(aos.loc.pos.eci, startkep);
174  tovernal = atan2(aos.loc.pos.extra.sun2earth.s.col[1], aos.loc.pos.extra.sun2earth.s.col[0]);
175  double startphase = fixangle(startkep.ma + startkep.raan - tovernal);
176 
177  kepstruc endkep;
178  eci2kep(los.loc.pos.eci, endkep);
179  tovernal = atan2(los.loc.pos.extra.sun2earth.s.col[1], los.loc.pos.extra.sun2earth.s.col[0]);
180  double endphase = fixangle(endkep.ma + endkep.raan - tovernal);
181 
182  double dphase = (1./86400.) * (endphase - startphase) / (los.loc.pos.eci.utc - aos.loc.pos.eci.utc);
183 
184  printf("00000001\t");
185  printf("%s\t", mjd2iso8601(aos.loc.pos.eci.utc).c_str());
186  printf("%s\t", to_mjd(aos.loc.pos.eci.utc).c_str());
187  printf("%s\t", to_double(DEGOF(aos.loc.pos.earthsep)).c_str());
188  printf("%s\t", to_double(DEGOF(startphase)).c_str());
189 
190  printf("%s\t", mjd2iso8601(los.loc.pos.eci.utc).c_str());
191  printf("%s\t", to_mjd(los.loc.pos.eci.utc).c_str());
192  printf("%s\t", to_double(DEGOF(los.loc.pos.earthsep)).c_str());
193  printf("%s\t", to_double(DEGOF(endphase)).c_str());
194 
195  printf("%s\t", to_double(DEGOF(dphase), 5).c_str());
196 
197  printf("2");
198  printf("\n");
199 
200  }
201  }
202  break;
203  }
204  }
205  }
206  }
207  }
208  else {
209  vector<double> amateurs = {59174.41688, 59177.03267, 59184.09772, 59187.79667, 59188.54722, 59189.95972};
210  for (double amateur : amateurs)
211  {
212  locstruc startloc;
213  lines2eci(amateur-2./1440., tles, startloc.pos.eci);
214  startloc.pos.eci.pass++;
215  pos_eci(startloc);
216  kepstruc startkep;
217  eci2kep(startloc.pos.eci, startkep);
218  tovernal = atan2(startloc.pos.extra.sun2earth.s.col[1], startloc.pos.extra.sun2earth.s.col[0]);
219  double startphase = fixangle(startkep.ma + startkep.raan - tovernal);
220 
221  locstruc endloc;
222  lines2eci(amateur+2./1440., tles, endloc.pos.eci);
223  endloc.pos.eci.pass++;
224  pos_eci(endloc);
225  kepstruc endkep;
226  eci2kep(endloc.pos.eci, endkep);
227  tovernal = atan2(endloc.pos.extra.sun2earth.s.col[1], endloc.pos.extra.sun2earth.s.col[0]);
228  double endphase = fixangle(endkep.ma + endkep.raan - tovernal);
229 
230  double dphase = (1./86400.) * (endphase - startphase) / (endloc.pos.eci.utc - startloc.pos.eci.utc);
231 
232  printf("00000000\t");
233  printf("%s\t", mjd2iso8601(startloc.pos.eci.utc).c_str());
234  printf("%s\t", to_mjd(startloc.pos.eci.utc).c_str());
235  printf("%s\t", to_double(DEGOF(startloc.pos.earthsep)).c_str());
236  printf("%s\t", to_double(DEGOF(startphase)).c_str());
237 
238  printf("%s\t", mjd2iso8601(endloc.pos.eci.utc).c_str());
239  printf("%s\t", to_mjd(endloc.pos.eci.utc).c_str());
240  printf("%s\t", to_double(DEGOF(endloc.pos.earthsep)).c_str());
241  printf("%s\t", to_double(DEGOF(endphase)).c_str());
242 
243  printf("%s\t", to_double(DEGOF(dphase), 5).c_str());
244 
245  printf("1");
246  printf("\n");
247  }
248  }
249 }
int32_t eci2kep(cartpos &eci, kepstruc &kep)
Definition: convertlib.cpp:2934
cartpos sun2earth
Definition: convertdef.h:605
double utcnow
Definition: fast_contacts.cpp:63
Target structure.
Definition: jsondef.h:1290
double utc
UTC of Position.
Definition: convertdef.h:161
static antstruc target
Definition: agent_antenna.cpp:160
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
double ma
Mean Anomoly.
Definition: convertdef.h:555
int32_t update_target(cosmosstruc *cinfo)
Update Track list.
Definition: jsonlib.cpp:11262
static float highest
Definition: get_contacts.cpp:58
int iretn
Definition: rw_test.cpp:37
int32_t wait(State state=State::RUN, double waitsec=10.)
Definition: agentclass.cpp:398
float earthsep
Separation between sun/satellite and sun/limbofearth vectors in radians.
Definition: convertdef.h:746
nodestruc node
Structure for summary information in node.
Definition: jsondef.h:4220
double iso86012utc(string date)
Definition: timelib.cpp:1305
int32_t extract_contents(string json)
Definition: jsonclass.cpp:16
rvector s
Location.
Definition: convertdef.h:163
bool data_isfile(string path, off_t size)
Definition: datalib.cpp:1895
static Agent * agent
ensure the Agent constructor creates only one instance per process
Definition: agent_001.cpp:45
static double minelev
Definition: get_contacts.cpp:60
Definition: agentclass.h:139
locstruc loc
Location structure.
Definition: jsondef.h:3596
#define DEGOF(rad)
Degrees of a Radian value.
Definition: math/constants.h:33
double fixangle(double angle)
Limit angle to range 0-2PI.
Definition: mathlib.cpp:2159
int32_t pos_eci(locstruc *loc)
Set ECI position.
Definition: convertlib.cpp:258
extrapos extra
Definition: convertdef.h:744
double raan
Right Ascension of the Ascending Node in radians.
Definition: convertdef.h:549
Classical elements structure.
Definition: convertdef.h:529
int32_t load_lines(string fname, vector< tlestruc > &lines)
Load TLE from file. TODO!!! Rename Function to loadTle and create new class for dealing with TLEs...
Definition: convertlib.cpp:3612
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
string nodename
Definition: agent_add_soh.cpp:54
locstruc loc
Definition: jsondef.h:1302
double col[3]
Definition: vector.h:55
Definition: jsonclass.h:11
cosmosstruc * cinfo
Definition: agentclass.h:346
cartpos eci
Definition: convertdef.h:737
FILE * fp
Definition: rw_test.cpp:38
string mjd2iso8601(double mjd)
Definition: timelib.cpp:1316
Definition: convertdef.h:876
int lines2eci(double utc, vector< tlestruc >lines, cartpos &eci)
Return position from TLE set.
Definition: convertlib.cpp:3155
float elfrom
Definition: jsondef.h:1296
string to_mjd(double value)
Definition: stringlib.cpp:298
string to_double(double value, uint16_t precision)
Definition: stringlib.cpp:285
Array ArrayContents
Definition: jsonclass.h:82
#define RADOF(deg)
Radians of a Degree value.
Definition: math/constants.h:29