00001
00002
00003
00004
00005
00006
00007
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
00019
00020
00021
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_;
00047 double pos_in_track_;
00048 double inertia_;
00049 static const double friction_;
00050 double actual_speed_;
00051 char sector_;
00052 Model_track* track_;
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
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
00081
00082
00083
00084
00085
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
00103 char next_position(char current_pos, signed char direction)
00104 {
00105 return ctrl_.next_position(current_pos, direction);
00106 }
00107 };
00108
00109 #endif