Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

NODE Class Reference

#include <node.hh>

Collaboration diagram for NODE:

Collaboration graph
[legend]

Public Methods

 NODE (NML_FORMAT_PTR, char *n, char *file, RCS_CMD_MSG *_startup_cmd=NULL)
virtual ~NODE ()
int initialize_node_variables ()
int initialize_command_buffer ()
int initialize_status_buffer ()
int initialize_world_model_buffer ()
void send_status (NODE_STATUS_TYPE, RCS_STAT_MSG *new_msg=NULL)
void check_timer (RCS_TIMER *)
void wait_for_timer (RCS_TIMER *)
void run (double time)
void run (RCS_TIMER *timer=NULL)
void task (double time)
void task (RCS_TIMER *timer=NULL)
virtual void error_handler ()
virtual void initialize_state_variables ()
virtual int cyclic_read ()
virtual int cyclic_process ()
virtual int cyclic_write ()
virtual int get_command_message ()
virtual int get_subordinates_status ()
virtual int get_oi_requests ()
virtual int read_world_model_in ()
virtual int read_sensors ()
virtual int process_oi_requests ()
virtual int sensory_processor ()
virtual int world_modeler ()
virtual int command_independant_planner ()
virtual int handle_generic_commands ()
virtual void send_command_to_all (RCS_CMD_MSG *)
virtual int execute_command ()
virtual void init ()
virtual void halt ()
virtual int output_to_actuators ()
virtual int send_oi_replies ()
virtual int write_world_model_out ()
virtual int send_subordinates_commands ()
virtual int send_status_message ()
virtual void check_if_valid ()

Data Fields

long state
long last_state
long last_state_of_last_command
long error_code
long cycle_count
NML_FORMAT_PTR format_ptr
char * config_file
NODE_SECTION current_section
NODE_STATUS_TYPE node_status
OPER_MODE_TYPE oper_mode
int num_of_subord
int all_subordinates_done
int valid
RCS_CMD_MSGcmd_in_msg
RCS_CMD_MSGlast_cmd_in_msg
RCS_STAT_MSGstatus_up_msg
RCS_WM_MSGwm_out_msg
NMLmsgoper_in_msg
int status_up_new
int cmd_in_new
int oper_in_new
int wm_out_new
NMLTYPE cmd_in_type
NMLTYPE last_cmd_in_type
NMLTYPE status_up_type
NMLTYPE oper_in_type
NMLTYPE wm_type
int cmd_in_type_new
RCS_TIMERcycle_timer
int cycle_timer_created
double cycle_time
double start_time
double finish_time
double last_cycle_time
double min_cycle_time
double max_cycle_time
double last_process_time
double min_process_time
double max_process_time
char * name
int name_length
long config_flags
int abort_flag

Private Attributes

RCS_CMD_CHANNELcmd_in
RCS_STAT_CHANNELstatus_up
RCS_WM_CHANNELwm_out
RCS_COMMAND_SOURCE_TYPE command_source
RCS_LINKED_LISTsub_list
RCS_LINKED_LISTwm_in_list
RCS_GENERIC_STATUSgeneric_status
RCS_CMD_MSGstartup_cmd

Friends

class RCS_EXPORT NODE_LINK
class RCS_OI
class CMD_OI

Constructor & Destructor Documentation

NODE::NODE NML_FORMAT_PTR    _format_ptr,
char *    _name,
char *    _config_file,
RCS_CMD_MSG   _startup_cmd = NULL
 

Definition at line 73 of file node.cc.

00075 {
00076   /* Indicate to user when the NODE is constructed. */
00077   rcs_print_debug (PRINT_NODE_CONSTRUCTORS,
00078                    "%s NODE constructor called.\n", _name);
00079 
00080   /* Set all the dynamically allocated pointers to NULL so the */
00081   /* so the destructors won't destroy them if they were never malloced, */
00082   /* and initialize some other NODE variables. */
00083   initialize_node_variables ();
00084 
00085   /* Set valid to zero incase we need to return from constructor early. */
00086   valid = 0;
00087 
00088   /* Store constructor parameters. */
00089   format_ptr = _format_ptr;
00090   config_file = _config_file;
00091   startup_cmd = _startup_cmd;
00092 
00093   /* Store the _name parameter in a new place. */
00094   name_length = strlen (_name);
00095   name = (char *) malloc (name_length + 1);
00096   if (NULL == name)
00097     {
00098       rcs_print_error ("NODE constructor: Couldn`t malloc space for name.\n");
00099       return;
00100     }
00101   strcpy (name, _name);
00102 
00103   /* Create an empty subordinate list. */
00104   sub_list = new RCS_LINKED_LIST;
00105   if (NULL == sub_list)
00106     {
00107       rcs_print_error ("%s: Couldn`t malloc space for list.\n", name);
00108       return;
00109     }
00110 
00111   wm_in_list = new RCS_LINKED_LIST;
00112   if (NULL == wm_in_list)
00113     {
00114       rcs_print_error ("%s: Couldn`t malloc space for list.\n", name);
00115       return;
00116     }
00117 
00118 
00119   if (-1 == initialize_command_buffer ())
00120     {
00121       return;
00122     }
00123   if (config_flags & NODE_SAVE_LAST_COMMAND && NULL != cmd_in)
00124     {
00125       if (NULL != cmd_in->cms)
00126         {
00127           last_cmd_in_msg = (RCS_CMD_MSG *) malloc (cmd_in->cms->size);
00128         }
00129     }
00130 
00131   if (config_flags & NODE_USE_STAT_BUFFER)
00132     {
00133       if (-1 == initialize_status_buffer ())
00134         {
00135           return;
00136         }
00137     }
00138 
00139   if (config_flags & NODE_USE_WM_BUFFER)
00140     {
00141       if (-1 == initialize_world_model_buffer ())
00142         {
00143           return;
00144         }
00145     }
00146 
00147   /* Set the valid flag to 1 since we made it this far. */
00148   valid = 1;
00149 
00150   /* Spawn servers for the command, status, and/or wm buffers if config */
00151   /* file says to. */
00152   nml_start ();
00153 
00154   /* Check if valid will set valid to zero if running this node could crash */
00155   /* the system. NODE::run() will do nothing if valid == 0 to avoid this. */
00156   check_if_valid ();
00157 
00158   rcs_print_debug (PRINT_NODE_CONSTRUCTORS,
00159                    "%s NODE constructor finished. (valid = %d)\n", _name,
00160                    valid);
00161 }

NODE::~NODE   [virtual]
 

Definition at line 457 of file node.cc.

00458 {
00459   /* Indicate to user when the node is deleted. */
00460   rcs_print_debug (PRINT_NODE_DESTRUCTORS, "%s: Destructor called.\n", name);
00461 
00462   if (NULL != name)
00463     {
00464       free (name);
00465       name = NULL;
00466     }
00467   if (NULL != generic_status)
00468     {
00469       delete generic_status;
00470       generic_status = NULL;
00471     }
00472   if (NULL != sub_list)
00473     {
00474       delete sub_list;
00475       sub_list = NULL;
00476     }
00477   if (NULL != wm_in_list)
00478     {
00479       delete wm_in_list;
00480       wm_in_list = NULL;
00481     }
00482   if (NULL != last_cmd_in_msg)
00483     {
00484       free (last_cmd_in_msg);
00485       last_cmd_in_msg = NULL;
00486     }
00487   nml_cleanup ();
00488 
00489   rcs_print_debug (PRINT_NODE_DESTRUCTORS, "Destructor finished.\n");
00490 }


Member Function Documentation

int NODE::initialize_node_variables  
 

Definition at line 173 of file node.cc.

Referenced by NODE().

00174 {
00175 
00176   /* Set all the dynamically allocated pointers to NULL so the */
00177   /* so the destructors won't destroy them if they were never malloced. */
00178   name = (char *) NULL;
00179   name_length = 0;
00180   cmd_in = (RCS_CMD_CHANNEL *) NULL;
00181   status_up = (RCS_STAT_CHANNEL *) NULL;
00182   wm_out = (RCS_WM_CHANNEL *) NULL;
00183 
00184   sub_list = (RCS_LINKED_LIST *) NULL;
00185   generic_status = (RCS_GENERIC_STATUS *) NULL;
00186   cycle_timer = (RCS_TIMER *) NULL;
00187   wm_in_list = (RCS_LINKED_LIST *) NULL;
00188 
00189   cmd_in_msg = (RCS_CMD_MSG *) NULL;
00190   last_cmd_in_msg = (RCS_CMD_MSG *) NULL;
00191 
00192   /* Initialize some other NODE variables. */
00193   node_status = NODE_INIT;
00194   status_up_new = 0;
00195   cmd_in_new = 1;
00196   cmd_in_type_new = 1;
00197   config_flags = default_node_config_flags;
00198   wm_out_new = 0;
00199   oper_in_new = 0;
00200   state = 0;
00201   error_code = 0;
00202   num_of_subord = 0;
00203   all_subordinates_done = 0;
00204   cycle_count = 0;
00205   abort_flag = 0;
00206   min_cycle_time = 360000;
00207   max_cycle_time = 0;
00208   min_process_time = 360000;
00209   max_process_time = 0;
00210   return (0);
00211 }

int NODE::initialize_command_buffer  
 

Definition at line 222 of file node.cc.

Referenced by NODE().

00223 {
00224 
00225   if (NULL == cmd_in)
00226     {
00227       /* Compute the name of the command buffer. */
00228       char *command_buffer_name;
00229       command_buffer_name =
00230         (char *) malloc (name_length + RCS_COMMAND_SUFFIX_LENGTH + 1);
00231       if (NULL == command_buffer_name)
00232         {
00233           rcs_print_error ("%s: malloc failed.\n", name);
00234           return (-1);
00235         }
00236       strcpy (command_buffer_name, name);
00237       strcat (command_buffer_name, RCS_COMMAND_SUFFIX);
00238 
00239       /* Create a channel to the command buffer. */
00240       cmd_in = new RCS_CMD_CHANNEL (format_ptr, command_buffer_name,
00241                                     name, config_file);
00242       free (command_buffer_name);
00243       command_buffer_name = (char *) NULL;
00244     }
00245 
00246   /* Make sure cmd in object created. */
00247   if (NULL == cmd_in)
00248     {
00249       rcs_print_error ("%s: Couldn`t create cmd_in channel.\n", name);
00250       return -1;
00251     }
00252 
00253   /* Check to see if cmd_in properly constructed. */
00254   if (!cmd_in->valid ())
00255     {
00256       rcs_print_error ("%s: Command buffer channel invalid. \n", name);
00257       return -1;
00258     }
00259 
00260   /* Create the startup command if none was passed to constructor. */
00261   int startup_cmd_created = 0;
00262   if (NULL == startup_cmd)
00263     {
00264       startup_cmd = new RCS_GENERIC_CMD;
00265       startup_cmd_created = 1;
00266     }
00267   if (NULL == startup_cmd)
00268     {
00269       rcs_print_error ("%s: Can't create startup command.\n", name);
00270       return -1;
00271     }
00272   ((RCS_GENERIC_CMD *) startup_cmd)->gen_id = GENERIC_INIT;
00273 
00274   /* Write the startup command into the command buffer. */
00275   if (-1 == cmd_in->write (startup_cmd))
00276     {
00277       rcs_print_error ("%s: Error on initial write to command buffer.\n",
00278                        name);
00279       return -1;
00280     }
00281 
00282   /* Read back the startup command. */
00283   if (-1 == cmd_in->read ())
00284     {
00285       rcs_print_error ("%s: Error on initial read of command buffer.\n",
00286                        name);
00287       return -1;
00288     }
00289   cmd_in_msg = (RCS_CMD_MSG *) cmd_in->get_address ();
00290   cmd_in_type = cmd_in_msg->type;
00291 
00292   /* Check to see if startup command matches command read back. */
00293   if (cmd_in_type != startup_cmd->type ||
00294       cmd_in_msg->serial_number != startup_cmd->serial_number)
00295     {
00296       rcs_print_error ("%s: Error initializing the command buffer. \n", name);
00297       return -1;
00298     }
00299 
00300   if (startup_cmd_created)
00301     {
00302       delete startup_cmd;
00303       startup_cmd = (RCS_CMD_MSG *) NULL;
00304     }
00305 
00306   /* Return "success". */
00307   return (0);
00308 }

int NODE::initialize_status_buffer  
 

Definition at line 319 of file node.cc.

Referenced by NODE().

00320 {
00321   if (status_up == NULL)
00322     {
00323       /* Compute the name of the status buffer. */
00324       char *status_buffer_name;
00325       status_buffer_name =
00326         (char *) malloc (name_length + RCS_STATUS_SUFFIX_LENGTH + 1);
00327       if (NULL == status_buffer_name)
00328         {
00329           rcs_print_error ("%s: malloc error.\n", name);
00330           return (-1);
00331         }
00332       strcpy (status_buffer_name, name);
00333       strcat (status_buffer_name, RCS_STATUS_SUFFIX);
00334 
00335       /* Create a new channel to the status buffer. */
00336       status_up = new RCS_STAT_CHANNEL (format_ptr, status_buffer_name,
00337                                         name, config_file);
00338 
00339       /* Free the space for the status_buffer_name */
00340       free (status_buffer_name);
00341       status_buffer_name = (char *) NULL;
00342     }
00343 
00344   /* Make sure status up object created. \n"); */
00345   if (NULL == status_up)
00346     {
00347       rcs_print_error ("%s: Couldn`t create status_up channel.\n", name);
00348       return (-1);
00349     }
00350 
00351   /* Check to see if status_up buffer properly constructed. */
00352   if (!status_up->valid ())
00353     {
00354       rcs_print_error ("%s: status_up object not properly constructed.\n",
00355                        name);
00356       return -1;
00357     }
00358 
00359   /* Create initial status object. */
00360   generic_status = new RCS_GENERIC_STATUS;
00361   if (NULL == generic_status)
00362     {
00363       rcs_print_error ("%s: Can't create initial status message.\n", name);
00364       return -1;
00365     }
00366   status_up_msg = generic_status;
00367   status_up_msg->node_status = NODE_INIT;
00368 
00369   /* Write initial status into status up buffer. */
00370   if (-1 == status_up->write (status_up_msg))
00371     {
00372       rcs_print_error ("%s: Error on initial write to status buffer.\n",
00373                        name);
00374       return -1;
00375     }
00376 
00377   /* Return "success". */
00378   return (0);
00379 }

int NODE::initialize_world_model_buffer  
 

Definition at line 390 of file node.cc.

Referenced by NODE().

00391 {
00392   if (NULL == wm_out)
00393     {
00394       /* Compute world model out buffer name. */
00395       char *wm_buffer_name;
00396       wm_buffer_name =
00397         (char *) malloc (name_length + RCS_WM_SUFFIX_LENGTH + 1);
00398       if (NULL == wm_buffer_name)
00399         {
00400           rcs_print_error ("%s: malloc error.\n", name);
00401         }
00402       strcpy (wm_buffer_name, name);
00403       strcat (wm_buffer_name, RCS_WM_SUFFIX);
00404 
00405       /* Create world model out channel. */
00406       wm_out =
00407         new RCS_WM_CHANNEL (format_ptr, wm_buffer_name, name, config_file);
00408 
00409       /* Release the memory for the buffer name. */
00410       free (wm_buffer_name);
00411       wm_buffer_name = NULL;
00412     }
00413 
00414   /* Check to see that wm_out created. */
00415   if (NULL == wm_out)
00416     {
00417       rcs_print_error ("%s: Can't create world model out channel. \n", name);
00418       return -1;
00419     }
00420 
00421   /* Check to see if wm_out properly constructed. */
00422   if (!wm_out->valid ())
00423     {
00424       rcs_print_error
00425         ("%s: World model out channel improperly constructed.\n", name);
00426       return -1;
00427     }
00428 
00429   /* Create initial world model message. */
00430   wm_out_msg = new RCS_GENERIC_WM;
00431   if (NULL == wm_out_msg)
00432     {
00433       rcs_print_error ("%s: Can't create initial world model message.\n",
00434                        name);
00435       return (-1);
00436     }
00437 
00438   if (-1 == wm_out->write (wm_out_msg))
00439     {
00440       rcs_print_error ("%s: Error on initial write to world model.\n", name);
00441       return -1;
00442     }
00443   delete wm_out_msg;
00444   wm_out_msg = NULL;
00445 
00446   /* Return "success". */
00447   return (0);
00448 }

void NODE::send_status NODE_STATUS_TYPE    new_status,
RCS_STAT_MSG   new_msg = NULL
 

Definition at line 1468 of file node.cc.

Referenced by get_command_message(), and init().

01469 {
01470   node_status = new_status;
01471   if (NULL != new_msg)
01472     {
01473       new_msg->node_status = new_status;
01474       status_up_msg = new_msg;
01475     }
01476   else
01477     {
01478       generic_status->node_status = new_status;
01479       status_up_msg = generic_status;
01480     }
01481   status_up_new = 1;
01482 }

void NODE::check_timer RCS_TIMER   _timer
 

Definition at line 581 of file node.cc.

Referenced by run().

00582 {
00583   double time_check;
00584   static old_cycle_count;
00585   if ((NULL != _timer) && (_timer != cycle_timer))
00586     {
00587       if (NULL != cycle_timer && cycle_timer_created)
00588         {
00589           delete cycle_timer;
00590         }
00591       cycle_timer = _timer;
00592       cycle_timer->sync ();
00593       cycle_timer_created = 0;
00594     }
00595 
00596   if (NULL != cycle_timer)
00597     {
00598       cycle_time = cycle_timer->timeout;
00599     }
00600 
00601   if (config_flags & NODE_CHECK_TIMES)
00602     {
00603       time_check = etime ();
00604       if (0 != cycle_count)
00605         {
00606           last_cycle_time = time_check - start_time;
00607           if (last_cycle_time < min_cycle_time)
00608             {
00609               min_cycle_time = last_cycle_time;
00610             }
00611           if (last_cycle_time > max_cycle_time)
00612             {
00613               max_cycle_time = last_cycle_time;
00614             }
00615           rcs_print_debug (PRINT_NODE_CYCLE_TIMES,
00616                            "%s: cycle times (last, min, max) = (%lf, %lf, %lf)\n",
00617                            name, last_cycle_time, min_cycle_time,
00618                            max_cycle_time); \}
00619       start_time = time_check;
00620     }
00621 }

void NODE::wait_for_timer RCS_TIMER   _timer
 

Definition at line 633 of file node.cc.

Referenced by run().

00634 {
00635   if (config_flags & NODE_CHECK_TIMES)
00636     {
00637       finish_time = etime ();
00638       last_process_time = finish_time - start_time;
00639       if (last_process_time < min_process_time)
00640         {
00641           min_process_time = last_process_time;
00642         }
00643       if (last_process_time > max_process_time)
00644         {
00645           max_process_time = last_process_time;
00646         }
00647       rcs_print_debug (PRINT_NODE_PROCESS_TIMES,
00648                        "%s: process times (last, min, max) = (%lf, %lf, %lf)\n",
00649                        name, last_process_time, min_process_time,
00650                        max_process_time);
00651     }
00652   if (NULL != cycle_timer)
00653     {
00654       int missed_cycles;
00655       missed_cycles = cycle_timer->wait ();
00656       if (missed_cycles > 0)
00657         {
00658           rcs_print_debug (PRINT_NODE_MISSED_CYCLES,
00659                            "%s: missed %d cycles.\n", name, missed_cycles);
00660         }
00661     }
00662   return;
00663 }

void NODE::run double    _time
 

Definition at line 814 of file node.cc.

Referenced by task().

00815 {
00816   if (_time != cycle_time)
00817     {
00818       if (NULL != cycle_timer && cycle_timer_created)
00819         {
00820           delete cycle_timer;
00821           cycle_timer = NULL;
00822         }
00823     }
00824   if (NULL == cycle_timer)
00825     {
00826       cycle_timer = new RCS_TIMER (_time);
00827       cycle_time = _time;
00828       cycle_timer_created = 1;
00829     }
00830   run ();
00831 }

void NODE::run RCS_TIMER   _timer = NULL
 

Definition at line 526 of file node.cc.

00527 {
00528   if (!valid)
00529     {
00530       rcs_print_error ("%s: NODE not properly constructed. \n", name);
00531       abort_flag = 1;
00532       return;
00533     }
00534 
00535   check_timer (_timer);
00536 
00537   cycle_count++;
00538   last_state = state;
00539   rcs_print_debug (PRINT_NODE_CYCLES, "%s: Cycles = %d\n", name, cycle_count);
00540 
00541   if (-1 == cyclic_read ())
00542     {
00543       error_handler ();
00544       return;
00545     }
00546 
00547   if (-1 == cyclic_process ())
00548     {
00549       error_handler ();
00550       return;
00551     }
00552 
00553   if (-1 == cyclic_write ())
00554     {
00555       error_handler ();
00556       return;
00557     }
00558 
00559   wait_for_timer (_timer);
00560 
00561   if (abort_flag)
00562     {
00563       rcs_print_debug (PRINT_NODE_ABORT, "%s aborting!\n", name);
00564       return;
00565     }
00566   return;
00567 }

void NODE::task double    time
 

Definition at line 845 of file node.cc.

00846 {
00847   if (time != cycle_time)
00848     {
00849       if (NULL != cycle_timer)
00850         {
00851           delete cycle_timer;
00852           cycle_timer = NULL;
00853         }
00854     }
00855   if (NULL == cycle_timer)
00856     {
00857       cycle_timer = new RCS_TIMER (time);
00858       cycle_time = time;
00859       cycle_timer_created = 1;
00860     }
00861   while (!abort_flag)
00862     {
00863       run ();
00864     }
00865 }

void NODE::task RCS_TIMER   timer = NULL
 

Definition at line 878 of file node.cc.

00879 {
00880   if ((NULL != cycle_timer) && cycle_timer_created)
00881     {
00882       delete cycle_timer;
00883       cycle_timer = NULL;
00884     }
00885 
00886   cycle_timer = timer;
00887   cycle_time = timer->timeout;
00888   cycle_timer_created = 0;
00889 
00890   while (!abort_flag)
00891     {
00892       run ();
00893     }
00894 }

void NODE::error_handler   [virtual]
 

Definition at line 1393 of file node.cc.

Referenced by run().

01394 {
01395   rcs_print_error ("%s: error occured in section %d.\n", name,
01396                    current_section);
01397   rcs_print_error ("(error_code = %d)\n", error_code);
01398   switch (current_section)
01399     {
01400     case NODE_GET_COMMAND_MESSAGE:
01401     case NODE_GET_SUBORDINATES_STATUS:
01402     case NODE_GET_OI_REQUESTS:
01403     case NODE_READ_WORLD_MODEL_IN:
01404     case NODE_WRITE_WORLD_MODEL_OUT:
01405     case NODE_SEND_SUBORDINATES_COMMANDS:
01406     case NODE_SEND_STATUS_MESSAGE:
01407       valid = 0;
01408       break;
01409     default:
01410       break;
01411     }
01412 }

void NODE::initialize_state_variables   [virtual]
 

Definition at line 1204 of file node.cc.

Referenced by init().

01205 {
01206 }

int NODE::cyclic_read   [virtual]
 

Definition at line 672 of file node.cc.

Referenced by run().

00673 {
00674   if (-1 == get_command_message ())     /* Read in cmd_in_message. */
00675     {
00676       current_section = NODE_GET_COMMAND_MESSAGE;
00677       return -1;
00678     }
00679 
00680   if (-1 == get_subordinates_status ()) /* Get status from subodinates. */
00681     {
00682       current_section = NODE_GET_SUBORDINATES_STATUS;
00683       return -1;;
00684     }
00685 
00686   if (-1 == read_world_model_in ())     /* Read wm_in_list */
00687     {
00688       current_section = NODE_READ_WORLD_MODEL_IN;
00689       return -1;
00690     }
00691 
00692   if (-1 == get_oi_requests ()) /* USER-DEFINED */
00693     {
00694       current_section = NODE_GET_OI_REQUESTS;
00695       return -1;
00696     }
00697 
00698   if (-1 == read_sensors ())    /* USER-DEFINED */
00699     {
00700       current_section = NODE_READ_SENSORS;
00701       return -1;
00702     }
00703   return 0;
00704 }

int NODE::cyclic_process   [virtual]
 

Definition at line 713 of file node.cc.

Referenced by run().

00714 {
00715   if (-1 == process_oi_requests ())     /* USER-DEFINED */
00716     {
00717       current_section = NODE_PROCESS_OI_REQUESTS;
00718       return -1;
00719     }
00720 
00721   if (-1 == sensory_processor ())       /* USER-DEFINED */
00722     {
00723       current_section = NODE_SENSORY_PROCESSOR;
00724       return -1;
00725     }
00726 
00727   if (-1 == world_modeler ())   /* USER-DEFINED */
00728     {
00729       current_section = NODE_WORLD_MODELER;
00730       return -1;
00731     }
00732 
00733   if (-1 == command_independant_planner ())     /* USER-DEFINED */
00734     {
00735       current_section = NODE_COMMAND_INDEPENDANT_PLANNER;
00736       return -1;
00737     }
00738 
00739   if (cmd_in_new || !(config_flags & NODE_EXECUTE_NEW_COMMANDS_ONLY))
00740     {
00741       if (-1 == handle_generic_commands ())     /* Call init or halt if recieved. */
00742         {
00743           current_section = NODE_HANDLE_GENERIC_COMMANDS;
00744           return -1;
00745         }
00746 
00747       if (cmd_in_type == RCS_GENERIC_CMD_TYPE)
00748         {
00749           return 0;
00750         }
00751 
00752       if (-1 == execute_command ())     /* USER-DEFINED */
00753         {
00754           current_section = NODE_EXECUTE_COMMAND;
00755           return -1;
00756         }
00757     }
00758   return 0;
00759 }

int NODE::cyclic_write   [virtual]
 

Definition at line 770 of file node.cc.

Referenced by run().

00771 {
00772   if (-1 == output_to_actuators ())     /* USER-DEFINED */
00773     {
00774       current_section = NODE_OUTPUT_TO_ACTUATORS;
00775       return -1;
00776     }
00777 
00778   if (-1 == send_oi_replies ()) /* USER-DEFINED */
00779     {
00780       current_section = NODE_SEND_OI_REPLIES;
00781       return -1;
00782     }
00783 
00784   if (-1 == write_world_model_out ())   /* USER-DEFINED */
00785     {
00786       current_section = NODE_WRITE_WORLD_MODEL_OUT;
00787       return -1;
00788     }
00789 
00790   if (-1 == send_subordinates_commands ())      /* Send Commands to Subs */
00791     {
00792       current_section = NODE_SEND_SUBORDINATES_COMMANDS;
00793       return -1;
00794     }
00795 
00796   if (-1 == send_status_message ())     /* Write status_up for my supervisor. */
00797     {
00798       current_section = NODE_SEND_STATUS_MESSAGE;
00799       return -1;
00800     }
00801   return (0);
00802 }

int NODE::get_command_message   [virtual]
 

Definition at line 914 of file node.cc.

Referenced by cyclic_read().

00915 {
00916   NMLTYPE read_value;
00917   if (config_flags & NODE_SAVE_LAST_COMMAND && NULL != cmd_in_msg &&
00918       NULL != last_cmd_in_msg)
00919     {
00920       memcpy (last_cmd_in_msg, cmd_in_msg, cmd_in_msg->size);
00921     }
00922 
00923   switch (read_value = cmd_in->read ())
00924     {
00925     case -1:
00926       rcs_print_error ("%s::get_command_message: Can`t read command in.\n",
00927                        name);
00928       return (-1);
00929     case 0:
00930       cmd_in_new = 0;
00931       return (0);
00932     default:
00933       cmd_in_new = 1;
00934       cmd_in_msg = cmd_in->get_address ();
00935       last_state_of_last_command = state;
00936       if (config_flags & NODE_RESET_STATE_ON_NEW_COMMAND)
00937         {
00938           state = 0;
00939         }
00940       if (config_flags & NODE_SEND_EXECUTING_ON_NEW_COMMAND)
00941         {
00942           send_status (NODE_EXECUTING);
00943         }
00944       node_status = NODE_EXECUTING;
00945       cmd_in_type_new = (cmd_in_type != read_value);
00946       last_cmd_in_type = cmd_in_type;
00947       cmd_in_type = read_value;
00948       rcs_print_debug (PRINT_COMMANDS_RECIEVED,
00949                        "%s: New cmd recieved. (type = %ld (0x%lX))\n", name,
00950                        cmd_in_type, cmd_in_type);
00951     }
00952   return (0);
00953 }

int NODE::get_subordinates_status   [virtual]
 

Definition at line 964 of file node.cc.

Referenced by cyclic_read().

00965 {
00966   NODE_LINK *node_link;
00967 
00968   if (0 == num_of_subord)
00969     {
00970       all_subordinates_done = 1;
00971       return (0);
00972     }
00973 
00974   if (NULL == sub_list)
00975     {
00976       return (-1);
00977     }
00978   all_subordinates_done = 1;
00979 
00980   node_link = (NODE_LINK *) sub_list->get_head ();
00981   while (NULL != node_link)
00982     {
00983       if (-1 == node_link->get_status ())
00984         {
00985           rcs_print_error ("%s::get_subodinates_status:\n", name);
00986           rcs_print_error ("   Error getting  %s's status.\n",
00987                            node_link->name);
00988           all_subordinates_done = 0;
00989           return (-1);
00990         }
00991       if (NODE_DONE != node_link->node_status)
00992         {
00993           all_subordinates_done = 0;
00994         }
00995       node_link = (NODE_LINK *) sub_list->get_next ();
00996     }
00997 
00998   return (0);
00999 }

int NODE::get_oi_requests   [virtual]
 

Definition at line 1010 of file node.cc.

Referenced by cyclic_read().

01011 {
01012   return (0);
01013 }

int NODE::read_world_model_in   [virtual]
 

Definition at line 1024 of file node.cc.

Referenced by cyclic_read().

01025 {
01026   NODE_LINK *node_link;
01027   if (NULL == wm_in_list)
01028     {
01029       return (-1);
01030     }
01031 
01032   node_link = (NODE_LINK *) wm_in_list->get_head ();
01033   while (NULL != node_link)
01034     {
01035       if (-1 == node_link->read_wm ())
01036         {
01037           rcs_print_error ("%s::read_world_model_in:\n", name);
01038           rcs_print_error ("   Error getting  %s's wm.\n", node_link->name);
01039           return (-1);
01040         }
01041       node_link = (NODE_LINK *) wm_in_list->get_next ();
01042     }
01043 
01044   return (0);
01045 }

int NODE::read_sensors   [virtual]
 

Definition at line 1070 of file node.cc.

Referenced by cyclic_read().

01071 {
01072   return (0);
01073 }

int NODE::process_oi_requests   [virtual]
 

Definition at line 1056 of file node.cc.

Referenced by cyclic_process().

01057 {
01058   return (0);
01059 }

int NODE::sensory_processor   [virtual]
 

Definition at line 1084 of file node.cc.

Referenced by cyclic_process().

01085 {
01086   return (0);
01087 }

int NODE::world_modeler   [virtual]
 

Definition at line 1098 of file node.cc.

Referenced by cyclic_process().

01099 {
01100   return (0);
01101 }

int NODE::command_independant_planner   [virtual]
 

Definition at line 1112 of file node.cc.

Referenced by cyclic_process().

01113 {
01114   return (0);
01115 }

int NODE::handle_generic_commands   [virtual]
 

Definition at line 1126 of file node.cc.

Referenced by cyclic_process().

01127 {
01128   RCS_GENERIC_CMD *gen_cmd;
01129 
01130 
01131   if (config_flags & NODE_USE_GENERIC_COMMANDS)
01132     {
01133       /* Check if the last command was a generic commands. */
01134       if ((RCS_GENERIC_CMD_TYPE == cmd_in_type) && (NULL != sub_list))
01135         {
01136           gen_cmd = ((RCS_GENERIC_CMD *) cmd_in_msg);
01137 
01138           /* Call the command function associated with this command. */
01139           switch (gen_cmd->gen_id)
01140             {
01141             case GENERIC_INIT:
01142               init ();
01143               break;
01144             case GENERIC_HALT:
01145               halt ();
01146               break;
01147             default:
01148               break;
01149             }
01150         }
01151     }
01152 
01153   return (0);
01154 }

void NODE::send_command_to_all RCS_CMD_MSG   cmd [virtual]
 

Definition at line 1166 of file node.cc.

Referenced by halt(), and init().

01167 {
01168   NODE_LINK *node_link;
01169 
01170   if (NULL != sub_list)
01171     {
01172       /* Send the generic command to all the subnodes. */
01173       node_link = (NODE_LINK *) sub_list->get_head ();
01174       while (NULL != node_link)
01175         {
01176           node_link->new_command (cmd);
01177           node_link = (NODE_LINK *) sub_list->get_next ();
01178         }
01179     }
01180 }

int NODE::execute_command   [virtual]
 

Definition at line 1191 of file node.cc.

Referenced by cyclic_process().

01192 {
01193   return (0);
01194 }

void NODE::init   [virtual]
 

Definition at line 1216 of file node.cc.

Referenced by handle_generic_commands().

01217 {
01218   switch (state)
01219     {
01220     case 0:
01221       send_command_to_all (cmd_in_msg);
01222       initialize_state_variables ();
01223       state = 1;
01224       break;
01225     case 1:
01226       if (all_subordinates_done)
01227         {
01228           send_status (NODE_DONE);
01229           state = 2;
01230         }
01231       break;
01232     case 2:
01233       break;
01234     default:
01235       break;
01236     }
01237 }

void NODE::halt   [virtual]
 

Definition at line 1247 of file node.cc.

Referenced by handle_generic_commands().

01248 {
01249   switch (state)
01250     {
01251     case 0:
01252       send_command_to_all (cmd_in_msg);
01253       abort_flag = 1;
01254       state = 1;
01255       break;
01256     case 1:
01257       break;
01258     default:
01259       break;
01260     }
01261 }

int NODE::output_to_actuators   [virtual]
 

Definition at line 1272 of file node.cc.

Referenced by cyclic_write().

01273 {
01274   return (0);
01275 }

int NODE::send_oi_replies   [virtual]
 

Definition at line 1287 of file node.cc.

Referenced by cyclic_write().

01288 {
01289   return (0);
01290 }

int NODE::write_world_model_out   [virtual]
 

Definition at line 1301 of file node.cc.

Referenced by cyclic_write().

01302 {
01303   if (wm_out_new)
01304     {
01305       wm_out_new = 0;
01306       if (NULL != wm_out_msg)
01307         {
01308           if (-1 == wm_out->write (wm_out_msg))
01309             {
01310               rcs_print_error ("%s: Can`t write to wm.", name);
01311               return (-1);
01312             }
01313         }
01314       rcs_print_debug (PRINT_NEW_WM, "%s: New wm. \n", name);
01315     }
01316   return (0);
01317 }

int NODE::send_subordinates_commands   [virtual]
 

Definition at line 1328 of file node.cc.

Referenced by cyclic_write().

01329 {
01330   NODE_LINK *node_link;
01331   if (NULL == sub_list)
01332     {
01333       return (-1);
01334     }
01335 
01336   node_link = (NODE_LINK *) sub_list->get_head ();
01337   while (NULL != node_link)
01338     {
01339       if (-1 == node_link->send_command ())
01340         {
01341           rcs_print_error ("%s::send_subordinates_commands:\n", name);
01342           rcs_print_error ("   Error sending %s a command.\n",
01343                            node_link->name);
01344           return (-1);
01345         }
01346       node_link = (NODE_LINK *) sub_list->get_next ();
01347     }
01348   return (0);
01349 }

int NODE::send_status_message   [virtual]
 

Definition at line 1360 of file node.cc.

Referenced by cyclic_write().

01361 {
01362   if (status_up_new)
01363     {
01364       status_up_new = 0;
01365       if (NULL != status_up_msg)
01366         {
01367           status_up_msg->serial_number = cmd_in_msg->serial_number;
01368           if (-1 == status_up->write (status_up_msg))
01369             {
01370               rcs_print_error
01371                 ("%s::send_status_up_message: Can`t send status.", name);
01372               return (-1);
01373             }
01374         }
01375       rcs_print_debug (PRINT_STATUS_SENT, "%s: New status sent. \n", name);
01376       rcs_print_debug (PRINT_STATUS_SENT,
01377                        " (type = %ld (0x%lX), status = %d)\n",
01378                        status_up_msg->type, status_up_msg->type,
01379                        status_up_msg->node_status);
01380     }
01381   return (0);
01382 }

void NODE::check_if_valid   [virtual]
 

Definition at line 1426 of file node.cc.

Referenced by NODE().

01427 {
01428   if (NULL == cmd_in)
01429     {
01430       valid = 0;
01431       return;
01432     }
01433   if (!cmd_in->valid ())
01434     {
01435       valid = 0;
01436       return;
01437     }
01438   if (config_flags & NODE_USE_STAT_BUFFER)
01439     {
01440       if (NULL == status_up)
01441         {
01442           valid = 0;
01443           return;
01444         }
01445       if (!status_up->valid ())
01446         {
01447           valid = 0;
01448           return;
01449         }
01450     }
01451   if (config_flags & NODE_USE_WM_BUFFER)
01452     {
01453       if (NULL == wm_out)
01454         {
01455           valid = 0;
01456           return;
01457         }
01458       if (!wm_out->valid ())
01459         {
01460           valid = 0;
01461           return;
01462         }
01463     }
01464 }


Friends And Related Function Documentation

friend class RCS_EXPORT NODE_LINK [friend]
 

Definition at line 131 of file node.hh.

friend class RCS_OI [friend]
 

Definition at line 132 of file node.hh.

friend class CMD_OI [friend]
 

Definition at line 133 of file node.hh.


Field Documentation

RCS_CMD_CHANNEL* NODE::cmd_in [private]
 

Definition at line 121 of file node.hh.

RCS_STAT_CHANNEL* NODE::status_up [private]
 

Definition at line 122 of file node.hh.

RCS_WM_CHANNEL* NODE::wm_out [private]
 

Definition at line 123 of file node.hh.

RCS_COMMAND_SOURCE_TYPE NODE::command_source [private]
 

Definition at line 124 of file node.hh.

RCS_LINKED_LIST* NODE::sub_list [private]
 

Definition at line 126 of file node.hh.

Referenced by NODE_LINK::NODE_LINK(), and NODE_LINK::~NODE_LINK().

RCS_LINKED_LIST* NODE::wm_in_list [private]
 

Definition at line 127 of file node.hh.

Referenced by NODE_LINK::NODE_LINK(), and NODE_LINK::~NODE_LINK().

RCS_GENERIC_STATUS* NODE::generic_status [private]
 

Definition at line 128 of file node.hh.

RCS_CMD_MSG* NODE::startup_cmd [private]
 

Definition at line 129 of file node.hh.

long NODE::state
 

Definition at line 135 of file node.hh.

long NODE::last_state
 

Definition at line 136 of file node.hh.

long NODE::last_state_of_last_command
 

Definition at line 137 of file node.hh.

long NODE::error_code
 

Definition at line 138 of file node.hh.

long NODE::cycle_count
 

Definition at line 139 of file node.hh.

NML_FORMAT_PTR NODE::format_ptr
 

Definition at line 140 of file node.hh.

char* NODE::config_file
 

Definition at line 141 of file node.hh.

NODE_SECTION NODE::current_section
 

Definition at line 142 of file node.hh.

NODE_STATUS_TYPE NODE::node_status
 

Definition at line 143 of file node.hh.

OPER_MODE_TYPE NODE::oper_mode
 

Definition at line 144 of file node.hh.

int NODE::num_of_subord
 

Definition at line 145 of file node.hh.

Referenced by NODE_LINK::NODE_LINK().

int NODE::all_subordinates_done
 

Definition at line 146 of file node.hh.

int NODE::valid
 

Definition at line 147 of file node.hh.

Referenced by NODE_LINK::NODE_LINK().

RCS_CMD_MSG* NODE::cmd_in_msg
 

Definition at line 148 of file node.hh.

RCS_CMD_MSG* NODE::last_cmd_in_msg
 

Definition at line 149 of file node.hh.

RCS_STAT_MSG* NODE::status_up_msg
 

Definition at line 150 of file node.hh.

RCS_WM_MSG* NODE::wm_out_msg
 

Definition at line 151 of file node.hh.

NMLmsg* NODE::oper_in_msg
 

Definition at line 152 of file node.hh.

int NODE::status_up_new
 

Definition at line 153 of file node.hh.

int NODE::cmd_in_new
 

Definition at line 154 of file node.hh.

int NODE::oper_in_new
 

Definition at line 155 of file node.hh.

int NODE::wm_out_new
 

Definition at line 156 of file node.hh.

NMLTYPE NODE::cmd_in_type
 

Definition at line 157 of file node.hh.

NMLTYPE NODE::last_cmd_in_type
 

Definition at line 158 of file node.hh.

NMLTYPE NODE::status_up_type
 

Definition at line 159 of file node.hh.

NMLTYPE NODE::oper_in_type
 

Definition at line 160 of file node.hh.

NMLTYPE NODE::wm_type
 

Definition at line 161 of file node.hh.

int NODE::cmd_in_type_new
 

Definition at line 162 of file node.hh.

RCS_TIMER* NODE::cycle_timer
 

Definition at line 164 of file node.hh.

int NODE::cycle_timer_created
 

Definition at line 165 of file node.hh.

double NODE::cycle_time
 

Definition at line 166 of file node.hh.

double NODE::start_time
 

Definition at line 167 of file node.hh.

double NODE::finish_time
 

Definition at line 168 of file node.hh.

double NODE::last_cycle_time
 

Definition at line 171 of file node.hh.

double NODE::min_cycle_time
 

Definition at line 172 of file node.hh.

double NODE::max_cycle_time
 

Definition at line 173 of file node.hh.

double NODE::last_process_time
 

Definition at line 175 of file node.hh.

double NODE::min_process_time
 

Definition at line 176 of file node.hh.

double NODE::max_process_time
 

Definition at line 177 of file node.hh.

char* NODE::name
 

Definition at line 181 of file node.hh.

Referenced by NODE_LINK::NODE_LINK(), NODE_LINK::get_status(), NODE_LINK::read_wm(), and NODE_LINK::send_command().

int NODE::name_length
 

Definition at line 182 of file node.hh.

long NODE::config_flags
 

Definition at line 183 of file node.hh.

Referenced by NODE_LINK::send_command().

int NODE::abort_flag
 

Definition at line 184 of file node.hh.


The documentation for this class was generated from the following files:
Generated on Sun Dec 2 15:58:57 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001