COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
event.h
Go to the documentation of this file.
1 /********************************************************************
2 * Copyright (C) 2015 by Interstel Technologies, Inc.
3 * and Hawaii Space Flight Laboratory.
4 *
5 * This file is part of the COSMOS/core that is the central
6 * module for COSMOS. For more information on COSMOS go to
7 * <http://cosmos-project.com>
8 *
9 * The COSMOS/core software is licenced under the
10 * GNU Lesser General Public License (LGPL) version 3 licence.
11 *
12 * You should have received a copy of the
13 * GNU Lesser General Public License
14 * If not, go to <http://www.gnu.org/licenses/>
15 *
16 * COSMOS/core is free software: you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public License
18 * as published by the Free Software Foundation, either version 3 of
19 * the License, or (at your option) any later version.
20 *
21 * COSMOS/core is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * Refer to the "licences" folder for further information on the
27 * condititons and terms to use this software.
28 ********************************************************************/
29 
30 #ifndef COSMOS_COMMAND_H
31 #define COSMOS_COMMAND_H
32 
37 
42 
43 #include "support/configCosmos.h"
44 #include "support/jsonlib.h"
45 #include "support/jsonobject.h"
46 
47 using std::string;
48 
49 #define MAXCOMMANDWORD 20
50 
51 namespace Cosmos {
52 
54 
57 class Event {
58 
59 public: // TODO: consider private?
60 
62  double mjd;
64  double utcexec=0.;
66  string name;
68  uint32_t type;
70  uint32_t flag;
72  string data;
74  string condition;
77  uint32_t true_count=0;
79  string event_string;
80 
81 public:
82 
84  Event();
85 
87  ~Event();
88 
90 
95  void set_command(string jstring);
96 
98 
101  void set_utcexec() { utcexec = currentmjd(0.); }
102 
104 
107  void set_actual() { flag |= EVENT_FLAG_ACTUAL; }
108 
110 
113  string get_name() { return name; }
114 
116 
119  string get_event_string();
120 
122 
125  double getUtc() { return mjd; }
126 
128 
131  string getTime() { return mjd2iso8601( getUtc() ); }
132 
134 
137  double getUtcExec() { return utcexec; }
138 
140 
143  string get_data() { return data; }
144 
146 
149  bool is_ready() { return (mjd <= currentmjd(0.)); }
150 
152 
155  bool is_repeat() { return (flag & EVENT_FLAG_REPEAT); }
156 
158 
161  bool is_command() { return (type & EVENT_TYPE_COMMAND); }
162 
164 
167  bool is_conditional(){ return (flag & EVENT_FLAG_CONDITIONAL); }
168 
170 
173  bool is_solo(){ return (flag & EVENT_FLAG_SOLO); }
174 
176 
179  bool is_alreadyrun(){ return (flag & EVENT_FLAG_TRUE); }
180  void set_alreadyrun(bool value){ if (value) flag |= EVENT_FLAG_TRUE; else flag &= ~EVENT_FLAG_TRUE; }
181 
182  string generator(
183  string name,
184  string data,
185  double utc,
186  string condition,
187  uint32_t flag
188  );
189 
190  string generator(eventstruc event);
191 
192  // JIMNOTE: this function (condition_true) needs a look at....
193  // OLDNOTE: seems to return nan from json_equation... how to use?
194  bool condition_true(cosmosstruc *cinfo);
195 
197 
204  friend std::ostream& operator<<(std::ostream& out, const Event& cmd);
205 
207 
212  friend bool operator==(const Event& cmd1, const Event& cmd2);
213 
214 }; // end of class Event
215 
216 } // end of namepsace Cosmos
217 
218 #endif // COSMOS_COMMAND_H
#define EVENT_TYPE_COMMAND
Definition: cosmos-defs.h:215
Definition: agentclass.cpp:54
bool is_alreadyrun()
Determines if the Event has already run.
Definition: event.h:179
uint32_t flag
Definition: event.h:70
string name
Definition: event.h:66
Class to manage Event information.
Definition: event.h:57
uint32_t true_count
Definition: event.h:77
bool already_ran
Definition: event.h:76
double mjd
Definition: event.h:62
string generator(string name, string data, double utc, string condition, uint32_t flag)
Definition: event.cpp:53
uint32_t type
Definition: event.h:68
#define EVENT_FLAG_TRUE
Event true last time.
Definition: cosmos-defs.h:173
double utcexec
Definition: event.h:64
string data
Definition: event.h:72
#define EVENT_FLAG_SOLO
Command Event should run by itself.
Definition: cosmos-defs.h:175
string condition
Definition: event.h:74
#define EVENT_FLAG_ACTUAL
Event actualy happened (versus being predicted).
Definition: cosmos-defs.h:164
bool is_repeat()
Determines if the Event repeatable.
Definition: event.h:155
#define EVENT_FLAG_REPEAT
Repeating event.
Definition: cosmos-defs.h:171
string get_event_string()
Retrieves Event information.
Definition: event.cpp:138
double getUtcExec()
Retrieves Event::utcexec.
Definition: event.h:137
void set_command(string jstring)
Sets Event information from a JSON formatted string.
Definition: event.cpp:118
bool is_conditional()
Determines if the Event is a conditional command.
Definition: event.h:167
JSON Support definitions.
Headers and definitions common to all COSMOS.
bool is_command()
Determines if the Event is a command.
Definition: event.h:161
string getTime()
Retrieves Event::mjd.
Definition: event.h:131
string event_string
Definition: event.h:79
Full COSMOS Event structure.
Definition: jsondef.h:1093
void set_utcexec()
Sets Event::utcexec to current time.
Definition: event.h:101
double getUtc()
Retrieves Event::mjd.
Definition: event.h:125
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
bool condition_true(cosmosstruc *cinfo)
Definition: event.cpp:158
bool is_solo()
Determines if the Event is a solo command.
Definition: event.h:173
Event()
Default constructor.
Definition: event.cpp:39
bool is_ready()
Determines if it is time for the Event to execute.
Definition: event.h:149
#define EVENT_FLAG_CONDITIONAL
Conditional event.
Definition: cosmos-defs.h:169
~Event()
Destructor.
Definition: event.cpp:51
friend bool operator==(const Event &cmd1, const Event &cmd2)
Equality operator.
Definition: event.cpp:103
string get_data()
Retrieves Event::data.
Definition: event.h:143
Definition: jsondef.h:4199
string mjd2iso8601(double mjd)
Definition: timelib.cpp:1316
void set_actual()
Sets Event::flag to indicate the event has actually executed (i.e. EVENT_FLAG_ACTUAL) ...
Definition: event.h:107
friend std::ostream & operator<<(std::ostream &out, const Event &cmd)
Extraction operator.
Definition: event.cpp:82
void set_alreadyrun(bool value)
Definition: event.h:180
string get_name()
Retrieves Event::name.
Definition: event.h:113