COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
command_generator.cpp File Reference
#include "support/configCosmos.h"
#include "support/datalib.h"
#include "support/jsonlib.h"
#include "support/timelib.h"
#include "agent/event.h"
#include "agent/scheduler.h"
Include dependency graph for command_generator.cpp:

Functions

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

Function Documentation

int main ( int  argc,
char *  argv[] 
)
41 {
42 
43  uint32_t flag = 0;
44  string data = "";
45  string condition = "";
46  string name= "";
47  double utc = 0.;
48 
49  string node = "";
50 
51  switch (argc)
52  {
53  case 8: // add command to the scheduler
54  {
55  node = string(argv[6]);
56  }
57  case 7: // set solo flag
58  {
59  if (atoi(argv[6]))
60  {
61  flag |= EVENT_FLAG_SOLO;
62  }
63  }
64  case 6: // set repeat flag
65  {
66  if (atoi(argv[5]))
67  {
68  flag |= EVENT_FLAG_REPEAT;
69  }
70  }
71  case 5: // set conditions
72  {
73  condition = argv[4];
74  if (condition != "{}")
75  {
76  flag |= EVENT_FLAG_CONDITIONAL;
77  }
78  }
79  case 4: // set time utc in mjd
80  {
81  switch (argv[3][0])
82  {
83  // add a few seconds to current time
84  case '+':
85  {
86  double seconds = atof(&argv[3][1]);
87  utc = currentmjd() + seconds / 86400.;
88  break;
89  }
90  default:
91  // use set time
92  {
93  utc = atof(argv[3]);
94  break;
95  }
96  }
97  }
98  case 3: // set command string
99  {
100  data = argv[2];
101  }
102  case 2: // set command name
103  {
104  name = argv[1];
105  break;
106  }
107  default:
108  {
109  cout << "The command generator produces the command string to be fed into the command\n"
110  "queue which is managed by agent_exec. Commands are a subset of events\n"
111  "in COSMOS." << endl << endl;
112 
113  cout << "Usage" << endl << endl;
114  cout << " command_generator [options]" << endl;
115  cout << " command_generator name command [time | +sec] [condition] [repeat_flag] [node]" << endl << endl;
116 
117 
118  cout << "Example" << endl << endl;
119  cout << " $ command_generator myCmd1 \"agent kauaicc_sim execsoh get_queue_size\" +10" << endl << endl;
120  cout << " This will run the command \"agent kauaicc_sim execsoh get_queue_size\" \n"
121  " with name 'myCmd' within 10 seconds from now." << endl << endl;
122 
123  cout << "Arguments" << endl << endl;
124 
125  cout << " name \t = name of the command, can be a string or combination of \n "
126  " \t alphanumeric characters (ex: myCmd1)" << endl;
127  cout << " command\t = the actual command to be executed, if more than one word \n"
128  " \t enclose the command string in quotes \n"
129  " \t (ex: \"agent kauaicc_sim execsoh get_queue_size\"" << endl;
130  cout << " time \t = optional argument to enter the desired modified julian date\n"
131  " \t (mjd). If not entered it will use the current time. \n"
132  " \t If '+' is used instead then the number of seconds can be\n"
133  " \t inserted. For 10 seconds in the future use +10" << endl;
134  cout << " condition \t = optional argument to enter a COSMOS condition\n"
135  " \t Shoold be in JSON. Empty {} will mean no condition \n";
136  cout << " repeat_flag \t = Optional repeat flag.\n"
137  " \t 0 or 1. \n";
138  cout << " node \t = optional argument to add the generated command to the command\n"
139  " \t queue on the specified node (ex: kauaicc_sim) " << endl;
140  return 0;
141  }
142  }
143 
144  Event event;
145 // cout << "Command string:" << endl;
146  // JIMNOTE: this could be done in the constructor
147 
148  cout << event.generator(name, data, utc, condition, flag) << endl << endl;
149 
150  if (!node.empty()) {
151  cout << "Adding command/event to node " << node << endl;
152  Scheduler scheduler(node);
153 
154  // Examples on how to use the scheduler class:
155  // event.name = "Track;FS701;20160930.145000;20160930.145500";
156  // event.data = "agent_tracker FS701 20160930.145000 20160930.145500";
157  // event.mjd = cal2mjd(2016, 9, 30, 14, 50, 0, 0);
158  // DateTime time( 2016, 10, 12, 14, 50, 1 );
159  // event.mjd = time.mjd;
160 
161  // cout << event.get_name() << endl;
162  // cout << event.get_data() << endl;
163  // cout << event.getTime() << endl;
164 
165  scheduler.addEvent(event);
166  COSMOS_SLEEP(0.1);
167  // scheduler.deleteEvent(event);
168  // scheduler.getEventQueueSize();
169  scheduler.getEventQueue();
170  }
171 }
Class to manage Event information.
Definition: event.h:57
Definition: scheduler.h:56
string generator(string name, string data, double utc, string condition, uint32_t flag)
Definition: event.cpp:53
#define EVENT_FLAG_SOLO
Command Event should run by itself.
Definition: cosmos-defs.h:175
#define EVENT_FLAG_REPEAT
Repeating event.
Definition: cosmos-defs.h:171
string name
Definition: cubesat2obj.cpp:6
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
#define EVENT_FLAG_CONDITIONAL
Conditional event.
Definition: cosmos-defs.h:169
static string node
Definition: agent_monitor.cpp:126