Subversion Repositories programming

Rev

Rev 331 | Rev 334 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 331 Rev 332
Line 4... Line 4...
4
// FIXME
4
// FIXME
5
// FIXME
5
// FIXME
6
// FIXME
6
// FIXME
7
void debug_puts (const char* s)
7
void debug_puts (const char* s)
8
{
8
{
9
#ifndef NO_DEBUG_PUTS
9
#ifndef QUIET
10
    puts (s);
10
    puts (s);
11
#endif
11
#endif
12
}
12
}
13
// FIXME
13
// FIXME
14
// FIXME
14
// FIXME
15
// FIXME
15
// FIXME
16
 
16
 
17
Elevator::Elevator (int num_floors) : num_floors(num_floors)
17
Elevator::Elevator (int num_floors) : num_floors(num_floors)
18
{
18
{
-
 
19
    int i;
-
 
20
 
19
    this->terminate = false;
21
    this->terminate = false;
20
    this->pause = false;
22
    this->pause = false;
21
    this->direction = IDLE;
23
    this->direction = IDLE;
22
    this->current_floor = 1.0;
24
    this->current_floor = 1.0;
23
    this->controller = NULL;
25
    this->controller = NULL;
24
 
26
 
25
    this->stop_at_floors = std::vector<bool> (num_floors+1, false);
27
    this->stop_at_floors.reserve (num_floors+1);
-
 
28
 
-
 
29
    for (i=0; i<num_floors+1; i++)
-
 
30
        this->stop_at_floors.push_back(i);
-
 
31
 
-
 
32
    printf ("created elevator 0x%x-- numfloors=%d\n", this, this->num_floors);
26
}
33
}
27
 
34
 
28
Elevator::~Elevator ()
35
Elevator::~Elevator ()
29
{
36
{
30
    this->pause = false;
37
    this->pause = false;
Line 98... Line 105...
98
            usleep (ELEVATOR_TIME_PAUSE_USEC);
105
            usleep (ELEVATOR_TIME_PAUSE_USEC);
99
        }
106
        }
100
 
107
 
101
        pthis->run_elevator_logic ();
108
        pthis->run_elevator_logic ();
102
 
109
 
-
 
110
#ifndef QUIET
103
        std::cout << pthis << " Position: " << pthis->current_floor << std::endl;
111
        std::cout << pthis << " Position: " << pthis->current_floor << std::endl;
-
 
112
#endif
104
        usleep (ELEVATOR_TIME_DELAY_USEC);
113
        usleep (ELEVATOR_TIME_DELAY_USEC);
105
    }
114
    }
106
}
115
}
107
 
116
 
108
void Elevator::thread_start ()
117
void Elevator::thread_start ()
Line 122... Line 131...
122
            /* Move towards the direction that has more floors to stop at.
131
            /* Move towards the direction that has more floors to stop at.
123
             * Prefer DOWN if there is a tie. */
132
             * Prefer DOWN if there is a tie. */
124
            if (has_floors_to_stop_at ())
133
            if (has_floors_to_stop_at ())
125
            {
134
            {
126
                direction = (floors_above_current () > floors_below_current ()) ? MOVE_UP : MOVE_DOWN;
135
                direction = (floors_above_current () > floors_below_current ()) ? MOVE_UP : MOVE_DOWN;
-
 
136
 
-
 
137
#ifndef QUIET
127
                printf ("changed direction to: %s\n", (direction == MOVE_UP) ? "MOVE_UP" : "MOVE_DOWN");
138
                printf ("changed direction to: %s\n", (direction == MOVE_UP) ? "MOVE_UP" : "MOVE_DOWN");
-
 
139
#endif
128
            }
140
            }
129
 
141
 
130
            break;
142
            break;
131
 
143
 
132
        case MOVE_UP:
144
        case MOVE_UP:
Line 309... Line 321...
309
    
321
    
310
    typedef std::vector<std::string> split_vector_type;
322
    typedef std::vector<std::string> split_vector_type;
311
    split_vector_type SplitVec;
323
    split_vector_type SplitVec;
312
    boost::split (SplitVec, s, boost::is_any_of(" "));
324
    boost::split (SplitVec, s, boost::is_any_of(" "));
313
 
325
 
314
    std::cout << "found " << SplitVec.size() << " strings" << std::endl;
-
 
315
 
-
 
316
    int i, val;
326
    int i, val;
317
    for (i=0; i<SplitVec.size(); i++)
327
    for (i=0; i<SplitVec.size(); i++)
318
    {
328
    {
319
        val = atoi (SplitVec[i].c_str());
329
        val = atoi (SplitVec[i].c_str());
320
 
330