#include "position.hpp"
#include "stop.hpp"
-typedef enum { CLOSED, OPEN } DoorStatus;
+class bad_direction { };
+
typedef std::list<Stop> StopList;
+enum State { STATE_IDLE, STATE_UP, STATE_DOWN, STATE_WAIT, STATE_OPEN_DOOR, STATE_CLOSE_DOOR };
+enum Event { EVT_IDLE, EVT_UP, EVT_DOWN, EVT_WAIT, EVT_OPEN_DOOR, EVT_CLOSE_DOOR };
+
class Elevator
{
public:
- Elevator ();
- Elevator (int starting_floor);
+ Elevator (int elevator_number);
+ Elevator (int starting_floor, int elevator_number);
void stop_at (Stop &stop);
float distance_from (Position& pos) const;
+ float distance_from (Stop& s) const;
void move ();
bool is_idle () const;
+ int getLoad () const;
+ bool willStopAt (int floor, Direction direction) const;
private:
- /* Callbacks into the GUI */
- void open_door () const;
- void close_door () const;
- void update_position () const;
+
+ /* State Machine: Helper Functions */
+ Event find_next_event () const;
+
+ /* State Machine: Transition Functions */
+ void transition_move_up ();
+ void transition_move_down ();
+ void transition_move_idle ();
+ void transition_open_door ();
+ void transition_close_door ();
+ void transition_begin_wait ();
+ void transition_continue_wait ();
/* Analyze the list of stops */
bool currently_at_stop () const;
/* Elevator Status Variables */
- DoorStatus door_;
Direction direction_;
- Position current_position_;
+ Position position_;
StopList stops_;
- const float ELEVATOR_STEP;
+ /* State Machine */
+ State state_;
+ int wait_;
+
+ /* Elevator Number: Used to make calls into the GUI */
+ int number_;
+
+ static const float ELEVATOR_STEP = 0.1;
};