-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestcase1.ini
106 lines (91 loc) · 2.35 KB
/
testcase1.ini
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
SIGNAL void testCase1() {
int pos;
int i, j;
int lastPulsePinValue;
int reached1, reached2, reached3;
int at_floor;
reached1 = 0;
reached2 = 0;
reached3 = 0;
pos = 0;
// close the doors
PORTC |= 1 << 8;
// let's go to floor 2
printf("going to floor 2\n");
PORTC |= 1 << 1;
// count the pulses to know what our position is
lastPulsePinValue = PORTC & (1 << 9);
for (i = 0; i < 800; ++i) {
if (lastPulsePinValue < (PORTC & (1 << 9)))
pos += TIM3_CCR1 ? 1 : -1;
lastPulsePinValue = PORTC & (1 << 9);
swatch(0.0025);
}
// now it's 2s later, do the calls to floor 1 and 3
printf("calling to floor 1 and 3\n");
PORTC ^= 1 << 1;
PORTC |= 1 << 0;
PORTC |= 1 << 2;
for (i = 0; i < 400; ++i) {
if (lastPulsePinValue < (PORTC & (1 << 9)))
pos += TIM3_CCR1 ? 1 : -1;
lastPulsePinValue = PORTC & (1 << 9);
swatch(0.0025);
}
// reset the pins
PORTC ^= 1 << 0;
PORTC ^= 1 << 2;
// we give the elevator 45s time to go to floors 1 and 3
for (j = 0; j < 45 && (!reached1 || !reached3); ++j) {
at_floor = 0;
// every second, check whether we are at a floor
if ((PORTC & (1 << 7)) && !TIM3_CCR1 && !TIM3_CCR2) {
if (pos >= -1 && pos <= 1 && !reached1) {
// reached floor 1
printf("arrived at floor 1\n");
reached1 = 1;
at_floor = 1;
}
if (pos >= 399 && pos <= 401 && !reached2) {
// reached floor 2
printf("arrived at floor 2\n");
reached2 = 1;
at_floor = 1;
}
if (pos >= 799 && pos <= 801 && !reached3) {
// reached floor 3
printf("arrived at floor 3\n");
reached3 = 1;
at_floor = 1;
}
}
// if we have stopped at a floor, we open the doors for 1s
if (at_floor)
PORTC ^= 1 << 8;
// wait 1s
for (i = 0; i < 400; ++i) {
if (lastPulsePinValue < (PORTC & (1 << 9)))
pos += TIM3_CCR1 ? 1 : -1;
lastPulsePinValue = PORTC & (1 << 9);
swatch(0.0025);
}
if (at_floor)
PORTC ^= 1 << 8;
}
if (!reached1) {
while (1) {
printf("Test-case failed: did not get to floor 1!\n");
swatch(0.02);
}
}
if (!reached3) {
while (1) {
printf("Test-case failed: did not get to floor 3!\n");
swatch(0.02);
}
}
while (1) {
printf("Test-case succeeded\n");
swatch(0.02);
}
}