COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
Cosmos::Event Class Reference

Class to manage Event information. More...

#include <event.h>

Collaboration diagram for Cosmos::Event:

Public Member Functions

 Event ()
 Default constructor. More...
 
 ~Event ()
 Destructor. More...
 
void set_command (string jstring)
 Sets Event information from a JSON formatted string. More...
 
void set_utcexec ()
 Sets Event::utcexec to current time. More...
 
void set_actual ()
 Sets Event::flag to indicate the event has actually executed (i.e. EVENT_FLAG_ACTUAL) More...
 
string get_name ()
 Retrieves Event::name. More...
 
string get_event_string ()
 Retrieves Event information. More...
 
double getUtc ()
 Retrieves Event::mjd. More...
 
string getTime ()
 Retrieves Event::mjd. More...
 
double getUtcExec ()
 Retrieves Event::utcexec. More...
 
string get_data ()
 Retrieves Event::data. More...
 
bool is_ready ()
 Determines if it is time for the Event to execute. More...
 
bool is_repeat ()
 Determines if the Event repeatable. More...
 
bool is_command ()
 Determines if the Event is a command. More...
 
bool is_conditional ()
 Determines if the Event is a conditional command. More...
 
bool is_solo ()
 Determines if the Event is a solo command. More...
 
bool is_alreadyrun ()
 Determines if the Event has already run. More...
 
void set_alreadyrun (bool value)
 
string generator (string name, string data, double utc, string condition, uint32_t flag)
 
string generator (eventstruc event)
 
bool condition_true (cosmosstruc *cinfo)
 

Public Attributes

double mjd
 
double utcexec =0.
 
string name
 
uint32_t type
 
uint32_t flag
 
string data
 
string condition
 
bool already_ran
 
uint32_t true_count =0
 
string event_string
 

Friends

std::ostream & operator<< (std::ostream &out, const Event &cmd)
 Extraction operator. More...
 
bool operator== (const Event &cmd1, const Event &cmd2)
 Equality operator. More...
 

Detailed Description

Class to manage Event information.

An Event is a collection of information related to a single occurance.

Constructor & Destructor Documentation

Cosmos::Event::Event ( )

Default constructor.

39  :
40  mjd(0),
41  utcexec(0),
42  name(""),
43  type(0),
44  flag(0),
45  data(""),
46  condition(""),
47  already_ran(false)
48 {}
uint32_t flag
Definition: event.h:70
string name
Definition: event.h:66
bool already_ran
Definition: event.h:76
double mjd
Definition: event.h:62
uint32_t type
Definition: event.h:68
double utcexec
Definition: event.h:64
string data
Definition: event.h:72
string condition
Definition: event.h:74
Cosmos::Event::~Event ( )

Destructor.

51 {}

Member Function Documentation

void Cosmos::Event::set_command ( string  jstring)

Sets Event information from a JSON formatted string.

Parameters
jstringEvent information string formatted as JSON

This function copies all Event information (from a JSON formatted string) into the current Event object

119 {
120  // clear Event information in agent
121  cosmosstruc * dummy = json_init();
122 // json_mapbaseentries(dummy);
123 
125 
126  // load Event information (from jstring) into agent
127  json_parse(jstring, dummy);
128 
129  mjd = dummy->event[0].utc;
130  utcexec = dummy->event[0].utcexec;
131  name = dummy->event[0].name;
132  type = dummy->event[0].type;
133  flag = dummy->event[0].flag;
134  data = dummy->event[0].data;
135  condition = dummy->event[0].condition;
136 }
uint32_t flag
Definition: event.h:70
string name
Definition: event.h:66
double mjd
Definition: event.h:62
int32_t json_parse(string jstring, cosmosstruc *cinfo)
Parse JSON using Name Space.
Definition: jsonlib.cpp:4799
uint32_t type
Definition: event.h:68
int32_t json_clear_cosmosstruc(int32_t type, cosmosstruc *cinfo)
Clear global data structure.
Definition: jsonlib.cpp:6268
double utcexec
Definition: event.h:64
cosmosstruc * json_init()
Initialize JSON pointer map.
Definition: jsonlib.cpp:454
string data
Definition: event.h:72
string condition
Definition: event.h:74
eventstruc
Definition: jsondef.h:156
vector< eventstruc > event
Single entry vector for event information.
Definition: jsondef.h:4250
Definition: jsondef.h:4199
void Cosmos::Event::set_utcexec ( )
inline

Sets Event::utcexec to current time.

This function is called after event execution and updates the execution time.

101 { utcexec = currentmjd(0.); }
double utcexec
Definition: event.h:64
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
void Cosmos::Event::set_actual ( )
inline

Sets Event::flag to indicate the event has actually executed (i.e. EVENT_FLAG_ACTUAL)

This function is called after event execution and updates the execution status.

107 { flag |= EVENT_FLAG_ACTUAL; }
uint32_t flag
Definition: event.h:70
#define EVENT_FLAG_ACTUAL
Event actualy happened (versus being predicted).
Definition: cosmos-defs.h:164
string Cosmos::Event::get_name ( )
inline

Retrieves Event::name.

Returns
string representing Event name
113 { return name; }
string name
Definition: event.h:66
string Cosmos::Event::get_event_string ( )

Retrieves Event information.

Returns
string representing Event information (as a JSON formatted string)
139 {
140  JSONObject jobj;
141  jobj.addElement("event_utc", JSONValue(mjd));
142  if (utcexec != 0.)
143  {
144  jobj.addElement("event_utcexec", JSONValue(utcexec));
145  }
146  jobj.addElement("event_name", JSONValue(name));
147  jobj.addElement("event_type", JSONValue(type));
148  jobj.addElement("event_flag", JSONValue(flag));
149  jobj.addElement("event_data", JSONValue(data));
151  {
152  jobj.addElement("event_condition", JSONValue(condition));
153  }
154 
155  return jobj.to_json_string();
156 }
uint32_t flag
Definition: event.h:70
string name
Definition: event.h:66
double mjd
Definition: event.h:62
Definition: jsonvalue.h:13
uint32_t type
Definition: event.h:68
double utcexec
Definition: event.h:64
string data
Definition: event.h:72
string condition
Definition: event.h:74
Definition: jsonobject.h:5
#define EVENT_FLAG_CONDITIONAL
Conditional event.
Definition: cosmos-defs.h:169
void addElement(string key, JSONValue value)
Definition: jsonobject.cpp:10
string to_json_string()
Definition: jsonobject.cpp:91
double Cosmos::Event::getUtc ( )
inline

Retrieves Event::mjd.

Returns
double representing Event start time
125 { return mjd; }
double mjd
Definition: event.h:62
string Cosmos::Event::getTime ( )
inline

Retrieves Event::mjd.

Returns
double representing Event start time
131 { return mjd2iso8601( getUtc() ); }
double getUtc()
Retrieves Event::mjd.
Definition: event.h:125
string mjd2iso8601(double mjd)
Definition: timelib.cpp:1316
double Cosmos::Event::getUtcExec ( )
inline

Retrieves Event::utcexec.

Returns
double representing Event execution time
137 { return utcexec; }
double utcexec
Definition: event.h:64
string Cosmos::Event::get_data ( )
inline

Retrieves Event::data.

Returns
string representing Event data
143 { return data; }
string data
Definition: event.h:72
bool Cosmos::Event::is_ready ( )
inline

Determines if it is time for the Event to execute.

Returns
True if Event is ready to execute, otherwise false
149 { return (mjd <= currentmjd(0.)); }
double mjd
Definition: event.h:62
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
bool Cosmos::Event::is_repeat ( )
inline

Determines if the Event repeatable.

Returns
True if Event is repeatable, otherwise false
155 { return (flag & EVENT_FLAG_REPEAT); }
uint32_t flag
Definition: event.h:70
#define EVENT_FLAG_REPEAT
Repeating event.
Definition: cosmos-defs.h:171
bool Cosmos::Event::is_command ( )
inline

Determines if the Event is a command.

Returns
True if Event is a command, otherwise false
161 { return (type & EVENT_TYPE_COMMAND); }
#define EVENT_TYPE_COMMAND
Definition: cosmos-defs.h:215
uint32_t type
Definition: event.h:68
bool Cosmos::Event::is_conditional ( )
inline

Determines if the Event is a conditional command.

Returns
True if Event is a conditional command, otherwise false
167 { return (flag & EVENT_FLAG_CONDITIONAL); }
uint32_t flag
Definition: event.h:70
#define EVENT_FLAG_CONDITIONAL
Conditional event.
Definition: cosmos-defs.h:169
bool Cosmos::Event::is_solo ( )
inline

Determines if the Event is a solo command.

Returns
True if Event is a solo command, otherwise false
173 { return (flag & EVENT_FLAG_SOLO); }
uint32_t flag
Definition: event.h:70
#define EVENT_FLAG_SOLO
Command Event should run by itself.
Definition: cosmos-defs.h:175
bool Cosmos::Event::is_alreadyrun ( )
inline

Determines if the Event has already run.

Returns
True if Event has already run, otherwise false
179 { return (flag & EVENT_FLAG_TRUE); }
uint32_t flag
Definition: event.h:70
#define EVENT_FLAG_TRUE
Event true last time.
Definition: cosmos-defs.h:173
void Cosmos::Event::set_alreadyrun ( bool  value)
inline
180 { if (value) flag |= EVENT_FLAG_TRUE; else flag &= ~EVENT_FLAG_TRUE; }
uint32_t flag
Definition: event.h:70
#define EVENT_FLAG_TRUE
Event true last time.
Definition: cosmos-defs.h:173
string Cosmos::Event::generator ( string  name,
string  data,
double  utc,
string  condition,
uint32_t  flag 
)
59  {
60 
61  this->name = name;
62  this->data = data;
63  this->mjd = mjd;
64  this->condition = condition;
65  this->flag = flag;
66  this->utcexec = 0.;
67  this->type = EVENT_TYPE_COMMAND;
68  event_string = "";
70 
71  return event_string;
72 }
#define EVENT_TYPE_COMMAND
Definition: cosmos-defs.h:215
uint32_t flag
Definition: event.h:70
string name
Definition: event.h:66
double mjd
Definition: event.h:62
uint32_t type
Definition: event.h:68
double utcexec
Definition: event.h:64
string data
Definition: event.h:72
string condition
Definition: event.h:74
string get_event_string()
Retrieves Event information.
Definition: event.cpp:138
string event_string
Definition: event.h:79
string Cosmos::Event::generator ( eventstruc  event)
74  {
75 
76  // returns a string with the event and also puts the string in "event_string"
77  return generator(event.name, event.data, event.utc, event.condition, event.flag);;
78 }
string generator(string name, string data, double utc, string condition, uint32_t flag)
Definition: event.cpp:53
char condition[(COSMOS_MAX_DATA)]
Condition that caused event, NULL if timed event.
Definition: jsondef.h:1133
double utc
Time event is to start.
Definition: jsondef.h:1096
char data[(COSMOS_MAX_DATA)]
Event specific data.
Definition: jsondef.h:1131
uint32_t flag
Event flags.
Definition: jsondef.h:1107
char name[40+1]
Name of event.
Definition: jsondef.h:1103
bool Cosmos::Event::condition_true ( cosmosstruc cinfo)
159 {
160  const char *cp = condition.c_str();
161  if (cinfo != nullptr)
162  { // Note: an equation must be enclosed by parentheses.
163  double r = json_equation(cp, cinfo);
164  if (fabs(r - 1.0) < std::numeric_limits<double>::epsilon())
165  {
166  ++true_count;
167  if (true_count >= 5 * (flag&EVENT_FLAG_PRIORITY)/32)
168  {
169  return true;
170  }
171  }
172  }
173  return false;
174 }
uint32_t flag
Definition: event.h:70
#define EVENT_FLAG_PRIORITY
3 bit flag, 0 - 7, see EVENT_SCALE_PRIORITY.
Definition: cosmos-defs.h:147
uint32_t true_count
Definition: event.h:77
static double epsilon
Definition: agent_exec-2-0.cpp:140
double json_equation(const char *&ptr, cosmosstruc *cinfo)
Return the results of a JSON equation.
Definition: jsonlib.cpp:4294
string condition
Definition: event.h:74

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const Event cmd 
)
friend

Extraction operator.

Parameters
outReference to ostream
cmdReference to const Event
Returns
Reference to modified ostream

Writes the given Event to the given output stream (in JSON format) and returns a reference to the modified ostream.

83 {
84  JSONObject jobj;
85  jobj.addElement("event_utc", JSONValue(cmd.mjd));
86  if (cmd.utcexec != 0.)
87  {
88  jobj.addElement("event_utcexec", JSONValue(cmd.utcexec));
89  }
90  jobj.addElement("event_name", JSONValue(cmd.name));
91  jobj.addElement("event_type", JSONValue(cmd.type));
92  jobj.addElement("event_flag", JSONValue(cmd.flag));
93  jobj.addElement("event_data", JSONValue(cmd.data));
94  if (cmd.flag & EVENT_FLAG_CONDITIONAL)
95  {
96  jobj.addElement("event_condition", JSONValue(cmd.condition));
97  }
98  out << std::setprecision(15) << jobj.to_json_string();
99  return out;
100 }
uint32_t flag
Definition: event.h:70
string name
Definition: event.h:66
double mjd
Definition: event.h:62
Definition: jsonvalue.h:13
uint32_t type
Definition: event.h:68
double utcexec
Definition: event.h:64
string data
Definition: event.h:72
string condition
Definition: event.h:74
Definition: jsonobject.h:5
#define EVENT_FLAG_CONDITIONAL
Conditional event.
Definition: cosmos-defs.h:169
void addElement(string key, JSONValue value)
Definition: jsonobject.cpp:10
string to_json_string()
Definition: jsonobject.cpp:91
bool operator== ( const Event cmd1,
const Event cmd2 
)
friend

Equality operator.

Parameters
cmd1First event
cmd2Second event
Returns
True if events are exactly the same, otherwise false
104 {
105  return ( cmd1.name==cmd2.name &&
106  cmd1.mjd==cmd2.mjd &&
107  cmd1.utcexec==cmd2.utcexec &&
108  cmd1.type==cmd2.type &&
109  cmd1.flag==cmd2.flag &&
110  cmd1.data==cmd2.data &&
111  cmd1.condition==cmd2.condition);
112 }
uint32_t flag
Definition: event.h:70
string name
Definition: event.h:66
double mjd
Definition: event.h:62
uint32_t type
Definition: event.h:68
double utcexec
Definition: event.h:64
string data
Definition: event.h:72
string condition
Definition: event.h:74

Member Data Documentation

double Cosmos::Event::mjd

Event start time (Modified Julian Date)

double Cosmos::Event::utcexec =0.

Event execution time (Coordinated Universal Time) – JIMNOTE: but appears to be using MJD in the code? should it be named mjdexec?

string Cosmos::Event::name

Event name

uint32_t Cosmos::Event::type

Event type

uint32_t Cosmos::Event::flag

Event flag

string Cosmos::Event::data

Event data

string Cosmos::Event::condition

Event condition

bool Cosmos::Event::already_ran

Event run indicators

uint32_t Cosmos::Event::true_count =0
string Cosmos::Event::event_string

Event information stored as a JSON string


The documentation for this class was generated from the following files: