COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
get_contacts.cpp File Reference
#include "support/convertlib.h"
#include "support/jsonlib.h"
#include "agent/agentclass.h"
#include "physics/physicslib.h"
#include "math/mathlib.h"
Include dependency graph for get_contacts.cpp:

Classes

struct  trackstruc
 

Functions

void propinit (size_t index, double dt)
 
void proptrack (size_t index, double utcnow)
 
void propthread (size_t index)
 
int main (int argc, char *argv[])
 

Variables

static Agentagent
 
static std::string nodename
 
static std::string tracknames
 
static std::vector< trackstructrack
 
static float highest = -RADOF(90.)
 
static double utcnow
 
static double minelev = RADOF(15.)
 

Function Documentation

void propinit ( size_t  index,
double  dt 
)
173 {
174  printf("Propagating Node %s forward %f seconds\n", track[index].name.c_str(), 86400.*(currentmjd()-track[index].target.loc.pos.eci.utc));
175  track[index].physics.mass = 1.;
176  track[index].physics.area = .01f;
177  gauss_jackson_init_eci(track[index].gjh, 12, 0, dt, track[index].target.loc.pos.eci.utc, track[index].target.loc.pos.eci, track[index].target.loc.att.icrf, track[index].physics, track[index].target.loc);
178  gauss_jackson_propagate(track[index].gjh, track[index].physics, track[index].target.loc, currentmjd());
179  track[index].running = true;
180  track[index].tca.elfrom = 0.;
181  track[index].visible = false;
182  track[index].target.utc = track[index].target.loc.utc;
183 }
ElapsedTime dt
Definition: agent_file3.cpp:183
static antstruc target
Definition: agent_antenna.cpp:160
void gauss_jackson_init_eci(gj_handle &gjh, uint32_t order, int32_t mode, double dt, double utc, cartpos ipos, qatt iatt, physicsstruc &physics, locstruc &loc)
Initialize Gauss-Jackson orbit using ECI state vector.
Definition: physicslib.cpp:2479
string name
Definition: cubesat2obj.cpp:6
vector< locstruc > gauss_jackson_propagate(gj_handle &gjh, physicsstruc &physics, locstruc &loc, double tomjd)
Definition: physicslib.cpp:2871
gj_handle gjh
Definition: agent_node.cpp:80
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
static std::vector< trackstruc > track
Definition: get_contacts.cpp:56
void proptrack ( size_t  index,
double  utcnow 
)
186 {
187 
188  gauss_jackson_propagate(track[index].gjh, track[index].physics, track[index].target.loc, utcnow);
189  update_target(agent->cinfo->node.loc, track[index].target);
190  if (track[index].target.elfrom > highest)
191  {
192  highest = track[index].target.elfrom;
193  }
194  switch (static_cast<uint8_t>(track[index].visible))
195  {
196  case 0:
197  if (track[index].target.elfrom > 0.)
198  {
199  track[index].aos = track[index].target;
200  track[index].highest = 0.;
201  track[index].startutc = utcnow;
202  track[index].visible = true;
203  track[index].peaked = false;
204  }
205  break;
206  case 1:
207  if (track[index].target.elfrom > track[index].highest)
208  {
209  track[index].highest = track[index].target.elfrom;
210  }
211  else if (!track[index].peaked)
212  {
213  track[index].peaked = true;
214  track[index].tca = track[index].target;
215  }
216  if (track[index].target.elfrom < 0.)
217  {
218  track[index].los = track[index].target;
219  track[index].visible = false;
220  if (track[index].tca.elfrom >= minelev)
221  {
222  kepstruc kep;
223  eci2kep(track[index].tca.loc.pos.eci, kep);
224  printf("%s %f %f ", track[index].name.c_str(), DEGOF(track[index].tca.loc.pos.earthsep), DEGOF(kep.beta));
225  printf("AOS0: %s %13.5f [ %6.1f %6.1f ] ", mjdToGregorian(track[index].aos.utc).c_str(), track[index].aos.utc, DEGOF(track[index].aos.azfrom), DEGOF(track[index].aos.elfrom));
226  printf("TCA[ %3.0f ]: %s %13.5f [ %6.1f %6.1f ] ", 86400.*(track[index].tca.utc-track[index].startutc), mjdToGregorian(track[index].tca.utc).c_str(), track[index].tca.utc, DEGOF(track[index].tca.azfrom), DEGOF(track[index].tca.elfrom));
227  printf("LOS0[ %3.0f ]: %s %13.5f [ %6.1f %6.1f ]\n", 86400.*(utcnow-track[index].startutc), mjdToGregorian(track[index].los.utc).c_str(), track[index].los.utc, DEGOF(track[index].los.azfrom), DEGOF(track[index].los.elfrom));
228  fflush(stdout);
229  }
230  }
231  break;
232  }
233 }
int32_t eci2kep(cartpos &eci, kepstruc &kep)
Definition: convertlib.cpp:2934
static antstruc target
Definition: agent_antenna.cpp:160
int32_t update_target(cosmosstruc *cinfo)
Update Track list.
Definition: jsonlib.cpp:11262
static float highest
Definition: get_contacts.cpp:58
static Agent * agent
Definition: get_contacts.cpp:36
static double utcnow
Definition: get_contacts.cpp:59
int32_t mjdToGregorian(double mjd, int32_t &year, int32_t &month, int32_t &day, int32_t &hour, int32_t &minute, int32_t &second)
Definition: timelib.cpp:1364
nodestruc node
Structure for summary information in node.
Definition: jsondef.h:4220
static double minelev
Definition: get_contacts.cpp:60
string name
Definition: cubesat2obj.cpp:6
locstruc loc
Location structure.
Definition: jsondef.h:3596
#define DEGOF(rad)
Degrees of a Radian value.
Definition: math/constants.h:33
vector< locstruc > gauss_jackson_propagate(gj_handle &gjh, physicsstruc &physics, locstruc &loc, double tomjd)
Definition: physicslib.cpp:2871
gj_handle gjh
Definition: agent_node.cpp:80
Classical elements structure.
Definition: convertdef.h:529
cosmosstruc * cinfo
Definition: agentclass.h:346
double beta
Solar Beta Angle in radians.
Definition: convertdef.h:544
static std::vector< trackstruc > track
Definition: get_contacts.cpp:56
void propthread ( size_t  index)
236 {
237  printf("Propagating Node %s forward %f seconds\n", track[index].name.c_str(), 86400.*(currentmjd()-track[index].target.loc.pos.eci.utc));
238  track[index].physics.mass = 1.;
239  track[index].physics.area = .01;
240  gauss_jackson_init_eci(track[index].gjh, 12, 0, 1., track[index].target.loc.pos.eci.utc, track[index].target.loc.pos.eci, track[index].target.loc.att.icrf, track[index].physics, track[index].target.loc);
241  gauss_jackson_propagate(track[index].gjh, track[index].physics, track[index].target.loc, currentmjd());
242  track[index].running = true;
243 
244  while (track[index].running)
245  {
246  track[index].control_mutex->lock();
247  gauss_jackson_propagate(track[index].gjh, track[index].physics, track[index].target.loc, utcnow);
248  update_target(agent->cinfo->node.loc, track[index].target);
249  if (track[index].target.elfrom > highest)
250  {
251  highest = track[index].target.elfrom;
252  }
253  switch ((uint8_t)track[index].visible)
254  {
255  case 0:
256  if (track[index].target.elfrom > 0.)
257  {
258  track[index].highest = 0.;
259  track[index].startutc = utcnow;
260  track[index].visible = true;
261  track[index].peaked = false;
262  printf("%s %13.5f %6.1f AOS0: %s\n", mjdToGregorian(utcnow).c_str(), utcnow, DEGOF(track[index].target.azfrom), track[index].name.c_str());
263  fflush(stdout);
264  }
265  break;
266  case 1:
267  if (track[index].target.elfrom > track[index].highest)
268  {
269  track[index].highest = track[index].target.elfrom;
270  }
271  else if (!track[index].peaked)
272  {
273  track[index].peaked = true;
274  printf("%s %13.5f %6.1f MAX: %4.0f sec %5.1f deg %s\n", mjdToGregorian(utcnow).c_str(), utcnow, DEGOF(track[index].target.azfrom), 86400.*(utcnow-track[index].startutc), DEGOF(track[index].target.elfrom), track[index].name.c_str());
275  }
276  if (track[index].target.elfrom < 0.)
277  {
278  track[index].visible = false;
279  printf("%s %13.5f %6.1f LOS0: %4.0f sec %s\n", mjdToGregorian(utcnow).c_str(), utcnow, DEGOF(track[index].target.azfrom), 86400.*(utcnow-track[index].startutc), track[index].name.c_str());
280  fflush(stdout);
281  }
282  break;
283  }
284  track[index].control_mutex->unlock();
285  COSMOS_USLEEP(1);
286  }
287 }
static antstruc target
Definition: agent_antenna.cpp:160
int32_t update_target(cosmosstruc *cinfo)
Update Track list.
Definition: jsonlib.cpp:11262
static float highest
Definition: get_contacts.cpp:58
static Agent * agent
Definition: get_contacts.cpp:36
void gauss_jackson_init_eci(gj_handle &gjh, uint32_t order, int32_t mode, double dt, double utc, cartpos ipos, qatt iatt, physicsstruc &physics, locstruc &loc)
Initialize Gauss-Jackson orbit using ECI state vector.
Definition: physicslib.cpp:2479
static double utcnow
Definition: get_contacts.cpp:59
int32_t mjdToGregorian(double mjd, int32_t &year, int32_t &month, int32_t &day, int32_t &hour, int32_t &minute, int32_t &second)
Definition: timelib.cpp:1364
nodestruc node
Structure for summary information in node.
Definition: jsondef.h:4220
string name
Definition: cubesat2obj.cpp:6
locstruc loc
Location structure.
Definition: jsondef.h:3596
#define DEGOF(rad)
Degrees of a Radian value.
Definition: math/constants.h:33
static int running
Definition: demlib.cpp:48
vector< locstruc > gauss_jackson_propagate(gj_handle &gjh, physicsstruc &physics, locstruc &loc, double tomjd)
Definition: physicslib.cpp:2871
gj_handle gjh
Definition: agent_node.cpp:80
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
cosmosstruc * cinfo
Definition: agentclass.h:346
static std::vector< trackstruc > track
Definition: get_contacts.cpp:56
int main ( int  argc,
char *  argv[] 
)
67 {
68  double period = 1.;
69 
70  switch (argc)
71  {
72  case 12:
73  tracknames += argv[11];
74  case 11:
75  tracknames += argv[10];
76  case 10:
77  tracknames += argv[9];
78  case 9:
79  tracknames += argv[8];
80  case 8:
81  tracknames += argv[7];
82  case 7:
83  tracknames += argv[6];
84  case 6:
85  tracknames += argv[5];
86  case 5:
87  tracknames += argv[4];
88  case 4:
89  tracknames += argv[3];
90  case 3:
91  period = atof(argv[2]);
92  case 2:
93  nodename = argv[1];
94  if (nodename.find(":") != string::npos)
95  {
96  minelev = RADOF(stof(nodename.substr(nodename.find(":")+1)));
97  nodename = nodename.substr(0, nodename.find(":"));
98  }
99  break;
100  default:
101  printf("Usage: get_contacts gsname[:minelev] [days [sat1 [sat2 [...]]]]\n");
102  exit (1);
103  }
104 
105  // Establish the command channel and heartbeat
106  if (!(agent = new Agent(nodename)))
107  {
108  std::cout << ": agent_setup_client failed (returned <"<<AGENT_ERROR_JSON_CREATE<<">)"<<std::endl;
110  }
111 
112  // Load Nodes
113 
114  std::vector <std::string> nodes;
115  int32_t iretn;
116  iretn = data_list_nodes(nodes);
117  for (size_t i=0; i<nodes.size(); ++i)
118  {
119  if (tracknames.size() == 0 || tracknames.find(nodes[i], 0) != std::string::npos)
120  {
121  std::string path = data_base_path(nodes[i]) + "/node.ini";
122  FILE *fp = fopen(path.c_str(), "r");
123  if (fp != nullptr)
124  {
125  int32_t type;
126  fscanf(fp, "{\"node_type\":%d", &type);
127  fclose(fp);
128  switch (type)
129  {
130  case NODE_TYPE_SATELLITE:
131  trackstruc ttrack;
132  ttrack.name = nodes[i];
133  cosmosstruc *cinfo = json_init();
134  iretn = json_setup_node(ttrack.name, cinfo);
135  if (iretn == 0)
136  {
137  if (iretn == 0 && (currentmjd()-cinfo->node.loc.pos.eci.utc) < 10.)
138  {
139  // Valid node. Initialize tracking and push it to list
140  ttrack.visible = false;
141  ttrack.peaked = false;
142  ttrack.target.type = cinfo->node.type;
143  ttrack.target.loc = cinfo->node.loc;
144  ttrack.target.utc = cinfo->node.loc.utc;
145  ttrack.physics = cinfo->node.phys;
146  track.push_back(ttrack);
147  json_destroy(cinfo);
148  }
149  }
150  }
151  }
152  }
153  }
154 
155  for (size_t i=0; i<track.size(); ++i)
156  {
157  propinit(i, 10.);
158  propinit(i, 1.);
159  }
160 
161  double utc;
162  for (utc=currentmjd(); utc<currentmjd()+period; utc+=1./86400)
163  {
164  for (size_t i=0; i<track.size(); ++i)
165  {
166  proptrack(i, utc);
167  }
168  }
169 
170 }
Definition: agent_control.cpp:165
static std::string tracknames
Definition: get_contacts.cpp:38
int32_t json_setup_node(jsonnode json, cosmosstruc *cinfo, bool create_flag)
Setup JSON Namespace using Node description JSON.
Definition: jsonlib.cpp:6869
double utc
UTC of Position.
Definition: convertdef.h:161
int i
Definition: rw_test.cpp:37
static Agent * agent
Definition: get_contacts.cpp:36
int iretn
Definition: rw_test.cpp:37
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
uint16_t type
Definition: jsondef.h:1294
string data_base_path(string node, string location, string agent, string filename)
Create data file path.
Definition: datalib.cpp:767
cosmosstruc * json_init()
Initialize JSON pointer map.
Definition: jsonlib.cpp:454
vector< string > data_list_nodes()
Get list of Nodes, directly.
Definition: datalib.cpp:583
bool visible
Definition: fast_contacts.cpp:52
double utc
Definition: jsondef.h:1292
nodestruc node
Structure for summary information in node.
Definition: jsondef.h:4220
Definition: cosmos-defs.h:90
std::vector< cosmosstruc > nodes
Definition: agent_data-2-0.cpp:57
static double minelev
Definition: get_contacts.cpp:60
Definition: agentclass.h:139
locstruc loc
Location structure.
Definition: jsondef.h:3596
void proptrack(size_t index, double utcnow)
Definition: get_contacts.cpp:185
Definition: eci2kep_test.cpp:33
string name
Definition: agent_control.cpp:170
bool peaked
Definition: fast_contacts.cpp:53
void json_destroy(cosmosstruc *cinfo)
Remove JSON pointer map.
Definition: jsonlib.cpp:491
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
targetstruc target
Definition: agent_control.cpp:168
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
void propinit(size_t index, double dt)
Definition: get_contacts.cpp:172
locstruc loc
Definition: jsondef.h:1302
physicsstruc physics
Definition: agent_control.cpp:169
cartpos eci
Definition: convertdef.h:737
FILE * fp
Definition: rw_test.cpp:38
#define AGENT_ERROR_JSON_CREATE
Definition: cosmos-errno.h:105
Definition: jsondef.h:4199
uint16_t type
Node Type as listed in NODE_TYPE.
Definition: jsondef.h:3562
static std::vector< trackstruc > track
Definition: get_contacts.cpp:56
physicsstruc phys
Definition: jsondef.h:3597
static std::string nodename
Definition: get_contacts.cpp:37
#define RADOF(deg)
Radians of a Degree value.
Definition: math/constants.h:29

Variable Documentation

Agent* agent
static
std::string nodename
static
std::string tracknames
static
std::vector<trackstruc> track
static
float highest = -RADOF(90.)
static
double utcnow
static
double minelev = RADOF(15.)
static