COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
get_contacts_tle.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_tle.cpp:

Classes

struct  trackstruc
 

Functions

void proptrack (size_t index, double utcnow)
 
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 utcstart
 
static double period = 1.
 
static double minelev = RADOF(15.)
 

Function Documentation

void proptrack ( size_t  index,
double  utcnow 
)
167 {
168  lines2eci(utcnow, track[index].tles, track[index].target.loc.pos.eci);
169  track[index].target.loc.pos.eci.pass++;
170  pos_eci(track[index].target.loc);
171  update_target(agent->cinfo->node.loc, track[index].target);
172  if (track[index].target.elfrom > highest)
173  {
174  highest = track[index].target.elfrom;
175  }
176  switch (static_cast<uint8_t>(track[index].visible))
177  {
178  case 0:
179  if (track[index].target.elfrom > 0.)
180  {
181  track[index].aos = track[index].target;
182  track[index].highest = 0.;
183  track[index].startutc = utcnow;
184  track[index].visible = true;
185  track[index].peaked = false;
186  }
187  break;
188  case 1:
189  if (track[index].target.elfrom > track[index].highest)
190  {
191  track[index].highest = track[index].target.elfrom;
192  }
193  else if (!track[index].peaked)
194  {
195  track[index].peaked = true;
196  track[index].tca = track[index].target;
197  }
198  if (track[index].target.elfrom < 0.)
199  {
200  track[index].los = track[index].target;
201  track[index].visible = false;
202  if (track[index].tca.elfrom >= minelev)
203  {
204  kepstruc kep;
205  eci2kep(track[index].tca.loc.pos.eci, kep);
206  printf("%s\t%f\t%f\t", track[index].name.c_str(), DEGOF(track[index].tca.loc.pos.earthsep), DEGOF(kep.beta));
207  printf("AOS0:\t%s\t%13.5f\t[\t%6.1f\t%6.1f\t]\t", mjdToGregorian(track[index].aos.utc).c_str(), track[index].aos.utc, DEGOF(track[index].aos.azfrom), DEGOF(track[index].aos.elfrom));
208  printf("TCA[ %3.0f ]:\t%s\t%13.5f\t[ %6.1f\t%6.1f ]\t", 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));
209  printf("LOS0[ %3.0f ]:\t%s\t%13.5f\t[ %6.1f\t%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));
210  fflush(stdout);
211  }
212  }
213  break;
214  }
215 }
int32_t eci2kep(cartpos &eci, kepstruc &kep)
Definition: convertlib.cpp:2934
double utcnow
Definition: fast_contacts.cpp:63
static antstruc target
Definition: agent_antenna.cpp:160
static double minelev
Definition: get_contacts_tle.cpp:60
int32_t update_target(cosmosstruc *cinfo)
Update Track list.
Definition: jsonlib.cpp:11262
static std::vector< trackstruc > track
Definition: get_contacts_tle.cpp:55
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 Agent * agent
Definition: get_contacts_tle.cpp:36
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
int32_t pos_eci(locstruc *loc)
Set ECI position.
Definition: convertlib.cpp:258
static float highest
Definition: get_contacts_tle.cpp:57
Classical elements structure.
Definition: convertdef.h:529
cosmosstruc * cinfo
Definition: agentclass.h:346
double beta
Solar Beta Angle in radians.
Definition: convertdef.h:544
int lines2eci(double utc, vector< tlestruc >lines, cartpos &eci)
Return position from TLE set.
Definition: convertlib.cpp:3155
int main ( int  argc,
char *  argv[] 
)
65 {
66 
67  utcstart = currentmjd();
68  switch (argc)
69  {
70  case 12:
71  tracknames += argv[11];
72  case 11:
73  tracknames += argv[10];
74  case 10:
75  tracknames += argv[9];
76  case 9:
77  tracknames += argv[8];
78  case 8:
79  tracknames += argv[7];
80  case 7:
81  tracknames += argv[6];
82  case 6:
83  tracknames += argv[5];
84  case 5:
85  tracknames += argv[4];
86  case 4:
87  tracknames += argv[3];
88  case 3:
89  period = atof(argv[2]);
90  if (period < 0.)
91  {
92  period = -period;
93  utcstart -= period;
94  }
95  case 2:
96  nodename = argv[1];
97  if (nodename.find(":") != string::npos)
98  {
99  minelev = RADOF(stof(nodename.substr(nodename.find(":")+1)));
100  nodename = nodename.substr(0, nodename.find(":"));
101  }
102  break;
103  default:
104  printf("Usage: get_contacts gsname[:minelev] [days [sat1 [sat2 [...]]]]\n");
105  exit (1);
106  }
107 
108  // Establish the command channel and heartbeat
109  if (!(agent = new Agent(nodename)))
110  {
111  std::cout << ": agent_setup_client failed (returned <"<<AGENT_ERROR_JSON_CREATE<<">)"<<std::endl;
113  }
114 
115  // Load Nodes
116 
117  std::vector <std::string> nodes;
118  int32_t iretn;
119  iretn = data_list_nodes(nodes);
120  for (size_t i=0; i<nodes.size(); ++i)
121  {
122  if (tracknames.size() == 0 || tracknames.find(nodes[i], 0) != std::string::npos)
123  {
124  std::string path = data_base_path(nodes[i]) + "/node.ini";
125  FILE *fp = fopen(path.c_str(), "r");
126  if (fp != nullptr)
127  {
128  int32_t type;
129  fscanf(fp, "{\"node_type\":%d", &type);
130  fclose(fp);
131  switch (type)
132  {
133  case NODE_TYPE_SATELLITE:
134  path = data_base_path(nodes[i]) + "/state.tle";
135  trackstruc ttrack;
136  ttrack.name = nodes[i];
137  iretn = load_lines(path, ttrack.tles);
138  if (iretn >= 0)
139  {
140  iretn = lines2eci(utcstart, ttrack.tles, ttrack.target.loc.pos.eci);
141  if (iretn >= 0)
142  {
143  // Valid node. Initialize tracking and push it to list
144  ttrack.visible = false;
145  ttrack.peaked = false;
146  ttrack.target.type = type;
147  track.push_back(ttrack);
148  }
149  }
150  }
151  }
152  }
153  }
154 
155  double utc;
156  for (utc=utcstart; utc<utcstart+period; utc+=1./86400)
157  {
158  for (size_t i=0; i<track.size(); ++i)
159  {
160  proptrack(i, utc);
161  }
162  }
163 
164 }
Definition: agent_control.cpp:165
int i
Definition: rw_test.cpp:37
static double period
Definition: get_contacts_tle.cpp:59
static double minelev
Definition: get_contacts_tle.cpp:60
static double utcstart
Definition: get_contacts_tle.cpp:58
int iretn
Definition: rw_test.cpp:37
static std::vector< trackstruc > track
Definition: get_contacts_tle.cpp:55
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
vector< tlestruc > tles
Definition: get_contacts_tle.cpp:45
static std::string tracknames
Definition: get_contacts_tle.cpp:38
vector< string > data_list_nodes()
Get list of Nodes, directly.
Definition: datalib.cpp:583
bool visible
Definition: fast_contacts.cpp:52
Definition: cosmos-defs.h:90
static Agent * agent
Definition: get_contacts_tle.cpp:36
std::vector< cosmosstruc > nodes
Definition: agent_data-2-0.cpp:57
Definition: agentclass.h:139
static std::string nodename
Definition: get_contacts_tle.cpp:37
string name
Definition: agent_control.cpp:170
bool peaked
Definition: fast_contacts.cpp:53
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
targetstruc target
Definition: agent_control.cpp:168
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
locstruc loc
Definition: jsondef.h:1302
cartpos eci
Definition: convertdef.h:737
FILE * fp
Definition: rw_test.cpp:38
#define AGENT_ERROR_JSON_CREATE
Definition: cosmos-errno.h:105
void proptrack(size_t index, double utcnow)
Definition: get_contacts_tle.cpp:166
int lines2eci(double utc, vector< tlestruc >lines, cartpos &eci)
Return position from TLE set.
Definition: convertlib.cpp:3155
#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 utcstart
static
double period = 1.
static
double minelev = RADOF(15.)
static