Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (2.31 KB)

1
#include <dragonfly_lib.h>
2
#include <wireless.h>
3
#include <xbee.h>
4

    
5
#include "../common/comm_station_robot.h"
6

    
7
#include "global.h"
8
#include "station_hardware.h"
9

    
10
#include "test_comm.h"
11
#include "test_bom.h"
12
#include "test_rangefinders.h"
13
#include "test_motors.h"
14
#include "test_encoders.h"
15

    
16
bool communication_ok=false;
17

    
18
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
void test_all (void)
30
{
31
        // 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 required. Stop." NL);
36
                return;
37
        }
38
        
39
        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
                usb_puts ("# Test (s)elf, (a)ll, (c)omm, (b)om, (r)angefinders, (m)otors, (e)ncoders" NL);
55

    
56
                char choice = usb_getc ();
57
                switch (choice) {
58
                        case 'c': case 'C': test_comm ();                               break;
59
                        case 'a': case 'A': test_all ();                                break; // test_all will test comm itself
60
                        case 'b': case 'B': if (require_comm ()) test_bom (true, true); break;
61
                        case 'r': case 'R': if (require_comm ()) test_rangefinders ();  break;
62
                        case 'm': case 'M': if (require_comm ()) test_motors ();        break;
63
                        case 'e': case 'E': if (require_comm ()) test_encoders ();      break;
64
                        case 's': case 'S': self_test ();                               break;
65
                        default: break; // ignore it
66
                }
67
        }
68
}
69

    
70
void server_main (void)
71
{
72
        // Set the orbs to green/yellow
73
        orbs_set (0,255,0, 255,127,0);
74

    
75
        while (1);
76
}
77

    
78
int main (void)
79
{
80
#include <dragonfly_lib.h>
81
#include <wireless.h>
82

    
83
    dragonfly_init(0);
84

    
85
    usb_init ();
86

    
87
        usb_puts(NL NL NL);
88
        usb_puts("# Diagnostic station version " version_string " starting" NL);
89

    
90
    orb_init_pwm ();
91
        hardware_init ();
92

    
93
        orb1_set (255, 0, 0); usb_puts("# Initializing wireless" NL);
94
        xbee_init ();
95
        wl_init();
96
        orb2_set (255, 0, 0); usb_puts("# Done" NL);
97

    
98
        if (button1_read ())
99
                        test_all ();
100

    
101
        if (button2_read ())
102
                server_main ();
103
        else
104
                interactive_main ();
105

    
106
        while (1);
107
}