Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/QNX4/Group5/Train.hpp

Go to the documentation of this file.
00001 /***
00002    NAME
00003      train
00004    PURPOSE
00005      Thingy for train class (Tentative)
00006    HISTORY
00007      bgoudem -- Mar 2, 2000: Created.
00008 ***/
00009 
00010 #ifndef __J2K__Train__Train_HPP__
00011 #define __J2K__Train__Train_HPP__
00012 
00013 #include <j2k/Fred/Boolean.hpp>
00014 #include <j2k/Fred/StdTypes.hpp>
00015 
00016 #include "timer.hh"
00017 //#include "board.hh"
00018 
00019 #include "model.hh"
00020 #include "constants.h"
00021 
00022 typedef Fake_controller_proxy Controller_proxy;
00023 
00024 /*
00025 class Train{
00026 
00027   void setActualSpeed(int actualSpeed);
00028   int getActualSpeed();  
00029   void setDesiredSpeed(int desiredSpeed);
00030   int getDesiredSpeed();  
00031   void setSpeedToDesired();  
00032 
00033   void setPosition(int position);
00034   int getPosition(){ return position;}  
00035   Direction getDirection(){ return direction;}
00036   void setDirection(Direction d);  
00037 
00038   int getCurrentSector();  
00039   int SDgetNextSector();  
00040   int SDgetAlternateSector();  
00041   
00042   BOOL SDrequireSector(); 
00043   void moveReverse();
00044   void moveForward();
00045 
00046   void parkOn(int position);  
00047   TrainStatus getTrainStatus(){return trainStatus;}
00048   void setTrainStatus(TrainStatus trainStatus);
00049 
00050   void waitOnNext();
00051   void stopWaiting();  
00052 
00053   void gotNextSector(BOOL requireSec);
00054 
00055  private:
00056   int currSec;
00057   int nextSec;
00058   int alternateSec;
00059   BOOL requireSec;
00060   
00061   int actualSpeed;
00062   int desiredSpeed;
00063   int position;
00064   Direction direction;
00065   TrainStatus trainStatus;
00066   int id;
00067 };
00068 */
00069 
00070 class Train : public Timer_thread
00071 {
00072 public:
00073   Train();
00074   ~Train();  
00075 
00076 private:
00077   UCHAR set_speed_;          // + = cw; - = anticw
00078   char direction_;
00079   SCHAR position_;
00080   char id_;
00081   Controller_proxy* controller_;
00082 
00083 public:
00084   Train(Controller_proxy* controller, char id, char initial_pos);
00085 
00086   // position tracking
00087   virtual void tick();        // attempt to track position
00088 
00089   char  get_position();       // returns 0 if lost track;
00090                               // this kills speed to 0 immediately
00091   void  set_position(char pos); // don't use if at all possible
00092 
00093   // speed
00094   UCHAR get_speed();
00095   void  set_speed(UCHAR speed);
00096 
00097   SCHAR get_direction();
00098   void  set_direction(SCHAR dir);
00099 
00100 private:
00101   DECLARE_MESSAGE_TABLE;
00102 };
00103 
00104 class Train_proxy
00105 {
00106 private:
00107   Train t_;
00108   TrainStatus stat_;
00109   int sector_;
00110   BOOL has_alt_;
00111   UCHAR user_speed_;
00112 
00113 public:
00114    Train_proxy(Controller_proxy* c, char id, char ipos, timespec& ts,
00115                int alg, int prio)
00116    : t_(c,id,ipos), stat_(WAITING), sector_(0), has_alt_(FALSE),
00117         user_speed_(0)
00118     {
00119         t_.start(ts, alg, prio);
00120     }
00121     int proxy_error() const
00122     {
00123         return t_.get_pid() == -1;
00124     }
00125     ~Train_proxy()
00126     {
00127         t_.stop();
00128     }
00129     char get_position();
00130     void set_position(char pos);
00131     UCHAR get_speed();
00132     void set_speed( UCHAR speed);
00133 
00134     SCHAR get_direction();
00135     void set_direction( SCHAR dir);
00136     void set_state(TrainStatus s)
00137     {
00138         stat_ = s;
00139     }
00140     TrainStatus get_state() const
00141     {
00142         return stat_;
00143     }
00144     void request_sector(int s)
00145     {
00146         sector_ = s;
00147     }
00148     BOOL requires_resource()
00149     {
00150         if(stat_ != PARKED &&
00151            CURRENTSECTOR[get_position()-1] == sector_)
00152             return TRUE;
00153         return FALSE;
00154     }
00155 
00156     BOOL get_alternate() const
00157     {
00158         return has_alt_;
00159     }
00160 
00161     void got_alternate(BOOL has_alt = TRUE)
00162     {
00163         has_alt_ = has_alt;
00164     }
00165 
00166     void set_user_speed( UCHAR user_speed)
00167     {
00168         user_speed_ = user_speed;
00169     }
00170     void sync_speeds()
00171     {
00172         set_speed(user_speed_);
00173     }
00174 };
00175 
00176 #endif

Generated on Sun Oct 14 18:46:38 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001