00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __CD_CONTROL_DECK__
00011 #define __CD_CONTROL_DECK__
00012
00013 #include <DSUtils/DSUtils.h>
00014 #include <DSimEngine2/DSimEngine2.h>
00015 #include "cd_control_module.h"
00016 #include "cd_control_system.h"
00017
00192 class cd_data_point;
00193 class cd_control_system;
00194
00199 #define CD_SYSTEM_GROUP "__cd_system_group"
00200
00204 #define CD_SIMULATION_STEP_EVENT "__cd_simulation_step_event"
00205
00213 class cd_control_deck
00214 {
00215 public:
00217 cd_control_deck(const char *control_setup_file = NULL);
00219 ~cd_control_deck();
00220
00221
00223 bool include_simulation(const char *setup_file);
00225 bool map_simulation_variable(const char *dsim_path,const char *cd_group,const char *cd_path);
00226
00227
00229 bool add_control_system(cd_control_system *system);
00230 cd_control_system *control_system_named(const char *name) const { return (cd_control_system *)systems.lookup(name); }
00231
00232
00234 void set_time_scale(double scale);
00236 double time_scale();
00238 void initialize();
00239
00241 void note_marked_variables(void (*note_callback)(void *ctx,const char *path,cd_data_point *pt,bool is_telemetry,bool is_command),void *ctx);
00243 void start();
00245 void resume_from_pause();
00247 ds_date run_step();
00249 ds_date delay_step(const ds_time_interval &delay);
00251 void run();
00252
00254 ds_date current_time();
00256 dsim_simulation *simulation();
00258 cd_control_module *load_control_module(const char *path,const char *type,const char *name,const char *ident=NULL);
00259
00260 void print_variables();
00261
00262 private:
00263 cd_control_deck (const cd_control_deck &r);
00264 cd_control_deck &operator= (const cd_control_deck &r);
00265
00266 private:
00267 void cd_xml_parser(const char *control_setup_file);
00268 void cd_text_parser(const char *control_setup_file);
00269 const char *parse_setup_file_v1(void *_doc);
00270
00271
00272 void remove_control_system(const char *name);
00273
00274
00275 void request_timer(const char *system,const char *module,double period,int code);
00276 void remove_timer(const char *system,const char *module,int code);
00277 void run_timer(const char *system,const char *module,int code);
00278
00279
00280 void note_background_task_finished(const char *system,const char *module,void *data,int code);
00281 void note_background_task_data(const char *system,const char *module,void *data,int code);
00282 void complete_background_task(const char *system,const char *module,void *data,int code);
00283 void handle_background_task_data(const char *system,const char *module,void *data,int code);
00284
00285
00286 void request_event_notification(const char *system,const char *module,const char *group,const char *event_name,int code);
00287 void trigger_event(const char *group,const char *event_name);
00288 void handle_event(const char *system,const char *module,int code);
00289
00290
00291 CD_DATA_REF create_data(const char *group,const char *path,int type,const char *units,const char *description,void *initial_value,bool is_system_group);
00292 CD_DATA_REF request_data(const char *group,const char *path,int type);
00293 const char *path_for_data(CD_DATA_REF point, const char *&group) const;
00294 bool delete_data(CD_DATA_REF point);
00295
00296
00297 void plog(const char *format,...);
00298 void error(const char *file,int line,const char *format,...);
00299 void vlog(const char *system,const char *module,const char *format,va_list arg);
00300 void verror(const char *system,const char *module,const char *file,int line,const char *format,va_list arg);
00301
00302
00303 double scale_seconds(double seconds);
00304
00305 dsim_simulation sim;
00306 dsim_variable sim_jd;
00307 dsim_variable sim_scale;
00308 ds_date next_sim_step;
00309 bool sim_active;
00310
00311 ds_character_hash systems;
00312 ds_character_hash events;
00313 ds_character_hash points;
00314 ds_dynamic_array_t timers;
00315 ds_dynamic_array_t set_variables;
00316 ds_dynamic_array_t mark_variables;
00317 ds_dynamic_array_t alias_variables;
00318
00319
00320 ds_dynamic_array_t task_completion;
00321
00322
00323 pthread_mutex_t run_lock;
00324 pthread_cond_t run_cond;
00325 ds_date next_runloop;
00326
00327 double _scale;
00328
00329 friend class cd_control_system;
00330
00331 };
00332
00333 #endif