Project

General

Profile

Revision 1393

Added by Chris Mar over 14 years ago

added wireless test to unit test framework

View differences:

trunk/code/projects/test/main.c
13 13
    // RUN_TEST(testlcd);
14 14
    // RUN_TEST(testlights);
15 15
    // RUN_TEST(testmotors);
16
    RUN_TEST(testrangefinder);
16
    // RUN_TEST(testrangefinder);
17 17
    // RUN_TEST(testtokenring);
18
     RUN_TEST(testwireless);
18 19
  }
19 20

  
20 21
  return 0;
trunk/code/projects/test/test_wireless.c
1
/**
2
 * Instructions:
3
 *  - wait for both robots to show ORB 1 RED and ORB 2 CYAN
4
 *  - press BUTTON 1 on robot to send first (ROBOT 1) - orbs should turn PURPLE
5
 *  - press BUTTON 2 on robot to receive first (ROBOT 2) - orbs should turn ORANGE
6
 *  - wait at least a second, then press BUTTON 1 on both robots SIMULTANEOUSLY
7
 *  - ROBOT 2 orbs should cycle ORANGE to RED to BLUE
8
 *  - then ROBOT 1 orbs should cycle PURPLE to RED to BLUE
9
 *  - then orbs on both robots should turn GREEN
10
 *  - test will reset to ORB 1 RED and ORB 2 CYAN
11
 *  - test should take ~7 seconds
12
 **/
13

  
14
#include <dragonfly_lib.h>
15
#include <wl_basic.h>
16

  
17
unsigned char* packet;
18

  
19
int testwireless(void) {
20
    int count = 0;
21
    int is_sender = 0;
22

  
23
    wl_basic_init_default();
24
    wl_set_channel(0x0E);
25

  
26
    orb1_set_color(RED);
27
    orb2_set_color(CYAN);
28
    delay_ms(500);
29
    while (count < 1) {
30
        if (button1_click()) {
31
            is_sender = 1;
32
            orb_set_color(PURPLE);
33
            count++;
34
        }
35
        if (button2_click()) {
36
            is_sender = 0;
37
            orb_set_color(ORANGE);
38
            count++;
39
        }
40
    }
41
    count = 0;
42

  
43
    delay_ms(1000);
44

  
45
    button1_wait();
46

  
47
    delay_ms(500);
48

  
49
    if (is_sender == 1) {
50
        delay_ms(1000);
51
        wl_basic_send_global_packet(1, "r", 2);
52
        usb_puts("sent RED packet\r\n");
53
        delay_ms(1000);
54
        wl_basic_send_global_packet(1, "b", 2);
55
        usb_puts("sent BLUE packet\r\n");
56
        while(count < 2) {
57
            packet = wl_basic_do();
58
            if (packet != 0) {
59
                if (current_packet.length > 0) {
60
                    if (packet[0] == 'r') {
61
                        orb_set_color(RED);
62
                        usb_puts("received RED packet\r\n");
63
                        count++;
64
                    }
65
                    else if (packet[0] == 'b') {
66
                        orb_set_color(BLUE);
67
                        usb_puts("received BLUE packet\r\n");
68
                        count++;
69
                    }
70
                }
71
            }
72
        }
73
    }
74
    else {
75
        while(count < 2) {
76
            packet = wl_basic_do();
77
            if (packet != 0) {
78
                if (current_packet.length > 0) {
79
                    if (packet[0] == 'r') {
80
                        orb_set_color(RED);
81
                        usb_puts("received RED packet\r\n");
82
                        count++;
83
                    }
84
                    else if (packet[0] == 'b') {
85
                        orb_set_color(BLUE);
86
                        usb_puts("received BLUE packet\r\n");
87
                        count++;
88
                    }
89
                }
90
            }
91
        }
92
        delay_ms(1000);
93
        wl_basic_send_global_packet(1, "r", 2);
94
        usb_puts("sent RED packet\r\n");
95
        delay_ms(1000);
96
        wl_basic_send_global_packet(1, "b", 2);
97
        usb_puts("sent BLUE packet\r\n");
98
    }
99
    delay_ms(1000);
100

  
101
	wl_terminate();
102

  
103
    orb_set_color(GREEN);
104

  
105
    delay_ms(2000);
106

  
107
    return 0;
108
}
109

  

Also available in: Unified diff