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

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

Go to the documentation of this file.
00001 /***
00002    NAME
00003      model
00004    PURPOSE
00005      Model for fake train/track until the lab's ready
00006    HISTORY
00007      b_goudre -- Feb 28, 2000: Created.
00008 ***/
00009 #ifndef __J2K__Train__Model_HPP__
00010 #define __J2K__Train__Model_HPP__
00011 
00012 #include "timer.hh"
00013 #include "constants.h"
00014 
00015 typedef enum SwitchStatus switchpoint_t;
00016 
00017 /*
00018 enum switchpoint_t
00019 {
00020   STRAIGHT,
00021   CURVED
00022 };
00023 */
00024 
00025 class Model_track
00026 {
00027 private:
00028   static const char   next_sector_[][][];
00029   static const char   relevant_switch_[];
00030   switchpoint_t points_[4];
00031 public:
00032   Model_track() {
00033     points_[0] = points_[1] = points_[2] = points_[3] = STRAIGHT;
00034   }
00035 
00036   void switch_point(int pt, switchpoint_t to)
00037   {
00038     points_[pt] = to;
00039   }
00040 };
00041 
00042     
00043 class Model_train
00044 {
00045 private:
00046   double speed_;              // -14..14
00047   double pos_in_track_;       // 0 to 1.0; at 14, takes 4 ticks to travel
00048   double inertia_;            // increase/decrease per period
00049   static const double friction_; // decrease when slowing
00050   double actual_speed_;       // real speed now
00051   char sector_;               // sector number
00052   Model_track* track_;        // track object for position updates
00053 
00054 public:
00055   Model_train(Model_track* t, char sect, double inert, double pos = 0.0);
00056 
00057   void   set_speed(signed char speed) { speed_ = speed; }
00058   double get_pos() const { return pos_in_track_; }
00059   char   get_sector() const { return sector_; }
00060 
00061   void tick();
00062 };
00063 
00064 
00065 
00066 class Fake_controller : public Timer_thread
00067 {
00068 private:
00069     Model_track track_;
00070     Model_train train1_, train2_, train4_;
00071 public:
00072     Fake_controller();
00073     virtual void tick();
00074 
00075     // exposed methods
00076     unsigned short get_position_mask();
00077     boolean set_train_speed(int num, signed char spd);
00078     boolean set_switch(int num, switchpoint_t pos);
00079 
00080     // I added this because I'm sick and tired of duplicating
00081     // the track layout!
00082     // NOTE: THIS IS NOT A MESSAGE-BASED METHOD!!! IT GETS CALLED
00083     // DIRECTLY (see proxy, below).  THIS IMPLIES IT RUNS IN YOUR
00084     // THREAD!  THERE'S A VERY GOOD REASON FOR THIS!
00085     // ALSO NOTE POSSIBLE RACE CONDITION!  BE CAREFUL!
00086     char next_position(char current_pos, signed char direction);
00087 private:
00088     DECLARE_MESSAGE_TABLE;
00089 };
00090 
00091 class Fake_controller_proxy
00092 {
00093 private:
00094     Fake_controller ctrl_;
00095 public:
00096     Fake_controller_proxy(int msec, int alg, int prio);
00097     ~Fake_controller_proxy();
00098 
00099     unsigned short get_position_mask();
00100     boolean set_train_speed(int num, signed char spd);
00101     boolean set_switch(int num, switchpoint_t pos);
00102     // NOTE!!! CALLED IN YOUR THREAD!!!
00103     char next_position(char current_pos, signed char direction)
00104     {
00105         return ctrl_.next_position(current_pos, direction);
00106     }
00107 };
00108 
00109 #endif /* __MODEL__DEFINED */

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