• Main Page
  • Modules
  • Classes
  • Files
  • File List

cd_control_module.h

00001 /*
00002  *  cd_control_module.h
00003  *  ControlDeck
00004  *
00005  *  Created by David Wilson on 2/13/08.
00006  *  Copyright 2008 Princeton Satellite Systems. All rights reserved.
00007  *
00008  */
00009 
00010 #ifndef __CD_CONTROL_MODULE__
00011 #define __CD_CONTROL_MODULE__
00012 
00013 #include <vector>
00014 
00015 #include <DSUtils/DSUtils.h>
00016 #include "cd_data_ref.h"
00017 
00018 using namespace std;
00019 
00020 class cd_control_system;
00021 class cd_data_point;
00022 class cd_control_module;
00023 
00028 typedef cd_data_ref CD_DATA_REF;
00029 typedef vector<CD_DATA_REF> cd_variables_vector;
00030 
00035 #define ERROR(...) error(__FILE__,__LINE__,__VA_ARGS__)
00036 
00041 typedef cd_control_module *(*cd_control_module_builder_func)(const char *name);
00042 
00043 void *cd_background_task_thread(void *data_struct);
00044 
00054 class cd_control_module
00055 {
00056     public:
00058         cd_control_module(const char *mod_name);
00060         virtual ~cd_control_module();
00061         
00062         // Initialization
00064         virtual void initialize_data();
00066         virtual void initialize_data_requests();
00068         virtual void setup_data(const char *command,const char *value);
00070         virtual void initialize();
00071         
00072         // Timed functions
00074         void request_timer(double period,int code);
00076         void remove_timer(int code);
00077         virtual void run_timer(int code);
00078         
00079         // Background thread functions
00081         void start_background_task(void *data,int code);
00083         virtual void run_background_task(void *data,int code);
00085         virtual void handle_intermediate_data(void *data,int code);
00087         virtual void complete_background_task(void *data,int code);
00088         
00089         // Called from a background thread function
00091         void return_intermediate_data(void *data,int code);
00092         
00093         // Event functions
00095         void request_event_notification(const char *group,const char *event_name,int code);
00097         void trigger_event(const char *group,const char *event_name);
00099         virtual void handle_event(int code);
00100         
00101         // Data functions
00103         CD_DATA_REF create_data(const char *group,const char *path,int type,const char *units,const char *description,void *initial_value = NULL);
00105         // SOMEDAY CD_DATA_REF request_data(const char *group,const char *path,int type) ; // __attribute__((deprecated));
00107         CD_DATA_REF request_data(const char *group,const char *path,int type,bool required=false,const char *units=NULL,const char *description=NULL);
00108 
00110         void mark_telemetry(CD_DATA_REF data);
00112         void mark_command(CD_DATA_REF data,const char *human_name = NULL);
00114         void mark_command_and_telemetry(CD_DATA_REF data,const char *human_name = NULL);
00116         void mark_telemetry_and_command(CD_DATA_REF data,const char *human_name = NULL);
00118         void add_attribute(CD_DATA_REF data,const char *attribute,const char *value);
00120         bool value_as_type(CD_DATA_REF data,int type,void *destination);
00122         void set_value_as_type(CD_DATA_REF data,int type,void *source, const char *msg = NULL);
00123         void add_setup(const char *command, const char *value);
00124         void execute_setups(void);
00125 
00126         // Logging
00128         void plog(const char *format,...);
00130         void error(const char *file,int line,const char *format,...);
00131         
00132         // Timing
00134         ds_date current_time();
00135         
00136         // Manifest
00138         unsigned int get_variables_count() const { return (unsigned int)_variables.size();}
00139         bool  variable_at_index(unsigned int idx) const;
00140         void clear_variables() { _variables.clear(); }
00141 
00142         // Introspection
00144         virtual void describe_setup();
00146         void describe_setup_command(const char *command,const char *description);
00148         void set_x(void *v) { x = v; }
00149     private:
00150                 cd_control_module (const cd_control_module &r);
00151                 cd_control_module &operator= (const cd_control_module &r);
00152 
00153     private:
00154         char *_name;
00155         cd_control_system *_system;
00156         cd_variables_vector _variables;
00157         ds_dynamic_array_t _setup_cmds;
00158         void *x;
00159 
00160         
00161         // control-system called manipulation functions
00162         void set_control_system(cd_control_system *system);
00163         void trigger_timer(int code);
00164         void note_background_task_finished(void *data,int code);
00165         void handle_background_task_finished(void *data,int code);
00166         void handle_background_task_data(void *data,int code);
00167     
00168     friend class cd_control_system;
00169     friend void *cd_background_task_thread(void *data_struct);
00170 };
00171 
00172 #endif

Generated on Fri Apr 5 2013 17:06:31 for ControlDeck by  doxygen 1.7.2