Subversion Repositories programming

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
321 ira 1
#include <cstdio>
2
#include <unistd.h>
3
using namespace std;
4
 
5
#include <boost/thread/thread.hpp>
6
#include <boost/bind.hpp>
7
 
8
#include "controller.h"
9
#include "elevator.h"
10
 
11
int main (int argc, char *argv[])
12
{
13
    int i = 0;
14
    Elevator e1 (10);
15
    Controller c (10, 5);
16
 
17
    vector<Elevator> elevators (5, Elevator (10));
18
 
19
    // start t1
20
    boost::thread t1 (boost::bind (e1.thread_entry, &e1));
21
 
22
#if 0
23
    // TEST MOVEMENT
24
 
25
    sleep (2);
26
    e1.set_direction (MOVE_UP);
27
    sleep (5);
28
    e1.thread_pause ();
29
    e1.set_direction (MOVE_DOWN);
30
    sleep (6);
31
    e1.thread_unpause ();
32
    e1.set_direction (IDLE);
33
    sleep (2);
34
#endif
35
 
36
#if 0
37
    // TEST floors_{above,below}_current() FUNCTIONS
38
    e1.push_button (3);
39
    printf ("AT POSITION 0\n");
40
    printf ("floors_above_current: %d\n", e1.floors_above_current());
41
    printf ("floors_below_current: %d\n\n", e1.floors_below_current());
42
 
43
    e1.goto_floor (2.9);
44
    printf ("AT POSITION 2.9\n");
45
    printf ("floors_above_current: %d\n", e1.floors_above_current());
46
    printf ("floors_below_current: %d\n\n", e1.floors_below_current());
47
 
48
    e1.goto_floor (3.1);
49
    printf ("AT POSITION 3.1\n");
50
    printf ("floors_above_current: %d\n", e1.floors_above_current());
51
    printf ("floors_below_current: %d\n\n", e1.floors_below_current());
52
 
53
    e1.goto_floor (3.0);
54
    printf ("AT POSITION 3.0\n");
55
    printf ("floors_above_current: %d\n", e1.floors_above_current());
56
    printf ("floors_below_current: %d\n\n", e1.floors_below_current());
57
#endif
58
 
59
#if 1
60
    // TEST MOVEMENT AGAIN
61
    e1.push_button (2);
62
    sleep (10);
63
    e1.push_button (1);
64
    e1.push_button (3);
65
    sleep (10);
66
#endif
67
 
68
    // notify t1 that it needs to stop
69
    e1.thread_exit ();
70
 
71
    // wait for t1 to stop
72
    t1.join ();
73
 
74
    return 0;
75
}
76