forked from Elsie4ever/DpmTeam2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WifiTest
144 lines (120 loc) · 3.57 KB
/
WifiTest
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package trotty02;
/*
* @author Sean Lawlor
* @date November 3, 2011
* @class ECSE 211 - Design Principle and Methods
*
* Modified by F.P. Ferrie
* February 28, 2014
* Changed parameters for W2014 competition
*
* Modified by Francois OD
* November 11, 2015
* Ported to EV3 and wifi (from NXT and bluetooth)
* Changed parameters for F2015 competition
*
* Modified by Michael Smith
* November 1, 2016
* Cleaned up print statements, old code, formatting
*
*/
import java.io.IOException;
import java.util.HashMap;
import trotty02.WifiConnection;
import lejos.hardware.Button;
import lejos.hardware.ev3.LocalEV3;
import lejos.hardware.lcd.TextLCD;
public class WifiTest {
/*
* Example call of the transmission protocol
* We use System.out.println() instead of LCD printing so that
* full debug output (e.g. the very long string containing the transmission)
* can be read on the screen or a remote console such as the
* EV3Control program via Bluetooth or WiFi
*/
/* *** INSTRUCTIONS ***
* There are two variables to set manually on the EV3 client:
* 1. SERVER_IP: the IP address of the computer running the server application
* 2. TEAM_NUMBER: your project team number
* */
private static final String SERVER_IP = "192.168.2.8";
private static final int TEAM_NUMBER = 2;
public static HashMap<String, Integer> t;
public static int role;
private static TextLCD LCD = LocalEV3.get().getTextLCD();
public WifiTest() {
}
public void run(){
LCD.clear();
/*
* WiFiConnection will establish a connection to the server and wait for data
* If the server is not running, this will throw an IOException
* If the server is running but the user has yet to press start on the Java GUI with some data,
* this will wait forever
* During the competition, this means you can start your code, place it on the field, and it will wait
* for data from the professor's computer
* If you need it to stop, access the robot via the EV3Control program and click "Stop Program"
* Alternatively, you can reset the robot but you risk SD card corruption
* Note that you can set the final argument debugPrint as false to disable printing to the LCD if desired.
*/
WifiConnection conn = null;
try {
System.out.println("Connecting...");
conn = new WifiConnection(SERVER_IP, TEAM_NUMBER, true);
} catch (IOException e) {
System.out.println("Connection failed");
}
LCD.clear();
/*
* This section of the code reads and prints the data received from the server,
* stored as a HashMap with String keys and Integer values.
*/
if (conn != null) {
HashMap<String, Integer> t = conn.StartData;
if (t == null) {
System.out.println("Failed to read transmission");
} else {
System.out.println("Transmission read:\n" + t.toString());
}
}
// Wait until user decides to end program
Button.waitForAnyPress();
}
public void getRole(){
if((t.get("BTN")) == 2)
role = 1; //builder
if((t.get("CTN")) == 2)
role = 2; //collector
}
public int getCorner(){
if(role == 1)
return (int)(t.get("BSC"));
if(role == 2)
return (int)(t.get("CSC"));
return 1;
}
public int getLRZy(){
return (int)(t.get("LRZy"));
}
public int getUGZy(){
return (int)(t.get("UGZy"));
}
public int getLRZx(){
return (int)(t.get("LRZx"));
}
public int getUGZx(){
return (int)(t.get("UGZx"));
}
public int getLGZy(){
return (int)(t.get("LGZy"));
}
public int getLGZx(){
return (int)(t.get("LGZx"));
}
public int getURZy(){
return (int)(t.get("URZy"));
}
public int getURZx(){
return (int)(t.get("URZx"));
}
}