Subversion Repositories programming

Rev

Blame | Last modification | View Log | RSS feed

#include <cstdio>
#include <unistd.h>
using namespace std;

#include <boost/thread/thread.hpp>
#include <boost/bind.hpp>

#include "controller.h"
#include "elevator.h"

int main (int argc, char *argv[])
{
    int i = 0;
    Elevator e1 (10);
    Controller c (10, 5);

    vector<Elevator> elevators (5, Elevator (10));

    // start t1
    boost::thread t1 (boost::bind (e1.thread_entry, &e1));

#if 0
    // TEST MOVEMENT

    sleep (2);
    e1.set_direction (MOVE_UP);
    sleep (5);
    e1.thread_pause ();
    e1.set_direction (MOVE_DOWN);
    sleep (6);
    e1.thread_unpause ();
    e1.set_direction (IDLE);
    sleep (2);
#endif

#if 0
    // TEST floors_{above,below}_current() FUNCTIONS
    e1.push_button (3);
    printf ("AT POSITION 0\n");
    printf ("floors_above_current: %d\n", e1.floors_above_current());
    printf ("floors_below_current: %d\n\n", e1.floors_below_current());

    e1.goto_floor (2.9);
    printf ("AT POSITION 2.9\n");
    printf ("floors_above_current: %d\n", e1.floors_above_current());
    printf ("floors_below_current: %d\n\n", e1.floors_below_current());

    e1.goto_floor (3.1);
    printf ("AT POSITION 3.1\n");
    printf ("floors_above_current: %d\n", e1.floors_above_current());
    printf ("floors_below_current: %d\n\n", e1.floors_below_current());

    e1.goto_floor (3.0);
    printf ("AT POSITION 3.0\n");
    printf ("floors_above_current: %d\n", e1.floors_above_current());
    printf ("floors_below_current: %d\n\n", e1.floors_below_current());
#endif

#if 1
    // TEST MOVEMENT AGAIN
    e1.push_button (2);
    sleep (10);
    e1.push_button (1);
    e1.push_button (3);
    sleep (10);
#endif

    // notify t1 that it needs to stop
    e1.thread_exit ();

    // wait for t1 to stop
    t1.join ();

    return 0;
}