Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / diagnostic_station / station / main.c @ 1160

History | View | Annotate | Download (2.38 KB)

1 1151 deffi
#include <dragonfly_lib.h>
2 1159 deffi
#include <wireless.h>
3
#include <xbee.h>
4 1151 deffi
5 1159 deffi
#include "../common/comm_station_robot.h"
6
7 1151 deffi
#include "global.h"
8
#include "station_hardware.h"
9
10 1152 deffi
#include "test_comm.h"
11 1151 deffi
#include "test_bom.h"
12
#include "test_rangefinders.h"
13 1159 deffi
#include "test_motors.h"
14 1151 deffi
#include "test_encoders.h"
15
16 1152 deffi
bool communication_ok=false;
17 1151 deffi
18 1152 deffi
bool require_comm (void)
19
{
20
        if (!communication_ok)
21
                communication_ok=test_comm ();
22
23
        if (!communication_ok)
24
                usb_puts ("Communications required. Stop." NL);
25
26
        return communication_ok;
27
}
28
29 1151 deffi
void test_all (void)
30
{
31 1153 deffi
        // test_all tests comm itself because we want to test comm, even if it
32
        // succeeded before (that's what test_all means).
33
        if (!test_comm ())
34
        {
35
                usb_puts ("Communications require. Stop." NL);
36
                return;
37
        }
38
39 1151 deffi
        test_bom (true, true);
40
        test_rangefinders ();
41
        test_encoders ();
42
        test_motors ();
43
}
44
45
void interactive_main (void)
46
{
47
        while (1)
48
        {
49
                // Set the orbs to green/green
50
                orbs_set (0,255,0, 0,255,0);
51
52
                usb_puts (NL);
53
                usb_puts ("Diagnostic station interactive mode" NL);
54 1159 deffi
                usb_puts ("Test (s)elf, (a)ll, (c)omm, (b)om, (r)angefinders, (m)otors, (e)ncoders" NL);
55 1151 deffi
56
                char choice = usb_getc ();
57
                switch (choice) {
58 1152 deffi
                        case 'c': case 'C': test_comm ();                               break;
59 1153 deffi
                        case 'a': case 'A': test_all ();                                break; // test_all will test comm itself
60 1152 deffi
                        case 'b': case 'B': if (require_comm ()) test_bom (true, true); break;
61
                        case 'r': case 'R': if (require_comm ()) test_rangefinders ();  break;
62 1159 deffi
                        case 'm': case 'M': if (require_comm ()) test_motors ();        break;
63 1152 deffi
                        case 'e': case 'E': if (require_comm ()) test_encoders ();      break;
64
                        case 's': case 'S': self_test ();                               break;
65 1151 deffi
                        default: break; // ignore it
66
//                                usb_puts("Received invalid input ");
67
//                                usb_putc(choice);
68
//                                usb_puts(NL);
69
                }
70
        }
71
}
72
73
void server_main (void)
74
{
75
        // Set the orbs to green/yellow
76
        orbs_set (0,255,0, 255,127,0);
77
78
        while (1);
79
}
80
81
int main (void)
82
{
83 1154 deffi
#include <dragonfly_lib.h>
84
#include <wireless.h>
85
86 1159 deffi
    dragonfly_init(0);
87 1154 deffi
88 1159 deffi
    usb_init ();
89 1151 deffi
90
        usb_puts(NL NL NL);
91
        usb_puts("Diagnostic station version " version_string " starting" NL);
92 1159 deffi
93
    orb_init_pwm ();
94 1151 deffi
        hardware_init ();
95 1159 deffi
96
        orb1_set (255, 0, 0); usb_puts("Initializing wireless" NL);
97
        xbee_init ();
98
        wl_init();
99
        orb2_set (255, 0, 0); usb_puts("Done" NL);
100
101 1160 deffi
        if (button1_read ())
102
                        test_all ();
103
104 1151 deffi
        if (button2_read ())
105
                server_main ();
106
        else
107
                interactive_main ();
108
109
        while (1);
110
}