Revision 539
spaces to tabs in colonet client
ColonetServerInterface.java | ||
---|---|---|
1 | 1 |
/* |
2 |
* ColonetServerInterface.java
|
|
3 |
* Gregory Tress
|
|
2 |
* ColonetServerInterface.java
|
|
3 |
* Gregory Tress
|
|
4 | 4 |
*/ |
5 | 5 |
|
6 | 6 |
import java.net.*; |
... | ... | |
29 | 29 |
{ |
30 | 30 |
/* Old packet structure: |
31 | 31 |
|
32 |
COMMAND PACKET STRUCTURE
|
|
33 |
1: SEND_TO_ROBOT
|
|
34 |
2: # of robot, or GLOBAL_DEST
|
|
35 |
3: COLONET_COMMMAND
|
|
36 |
4: message code (i.e. ORB_SET)
|
|
37 |
5: any data, as many that fit in the packet
|
|
32 |
COMMAND PACKET STRUCTURE
|
|
33 |
1: SEND_TO_ROBOT
|
|
34 |
2: # of robot, or GLOBAL_DEST
|
|
35 |
3: COLONET_COMMMAND
|
|
36 |
4: message code (i.e. ORB_SET)
|
|
37 |
5: any data, as many that fit in the packet
|
|
38 | 38 |
|
39 | 39 |
REQUEST PACKET STRUCTURE |
40 |
1: REQUEST_FROM_SERVER
|
|
41 |
2: # of robot
|
|
42 |
3: COLONET_REQUEST
|
|
43 |
4: ???
|
|
40 |
1: REQUEST_FROM_SERVER
|
|
41 |
2: # of robot
|
|
42 |
3: COLONET_REQUEST
|
|
43 |
4: ???
|
|
44 | 44 |
|
45 |
9/12/07 New server interface structure
|
|
46 |
Client will no longer send full robot packets to the server.
|
|
47 |
Commands will be defined as necessary.
|
|
45 |
9/12/07 New server interface structure
|
|
46 |
Client will no longer send full robot packets to the server.
|
|
47 |
Commands will be defined as necessary.
|
|
48 | 48 |
*/ |
49 | 49 |
|
50 | 50 |
//General Colonet Interface |
... | ... | |
100 | 100 |
public static final String ORB_SET_NUM = "21"; //0x15 |
101 | 101 |
public static final String ORB_SEND = "22"; //0x16 |
102 | 102 |
|
103 |
Colonet colonet; //save reference to the entire applet locally
|
|
103 |
Colonet colonet; //save reference to the entire applet locally
|
|
104 | 104 |
Socket socket; |
105 | 105 |
OutputStreamWriter out; |
106 | 106 |
BufferedReader reader; |
... | ... | |
108 | 108 |
JTextArea log, txtMatrix; |
109 | 109 |
|
110 | 110 |
/* |
111 |
* FUNCTION IMPLEMENTATIONS
|
|
111 |
* FUNCTION IMPLEMENTATIONS
|
|
112 | 112 |
*/ |
113 | 113 |
|
114 | 114 |
/** |
... | ... | |
116 | 116 |
* reference must be provided to ensure that data is routed correctly. |
117 | 117 |
* |
118 | 118 |
* @param colonet The Colonet object to save locally. This reference cannot be changed once the |
119 |
* ColonetSreverInterface has been contsructed.
|
|
119 |
* ColonetSreverInterface has been contsructed.
|
|
120 | 120 |
* @throws NullPointerException if colonet is null |
121 | 121 |
* |
122 | 122 |
*/ |
... | ... | |
192 | 192 |
return; |
193 | 193 |
} catch (IOException e) { |
194 | 194 |
log.append("IO Exception.\n"); |
195 |
err("Could not create socket to " + strHost + ".\n" + e);
|
|
195 |
err("Failed to connect to " + strHost + ".\n" + e);
|
|
196 | 196 |
return; |
197 | 197 |
} catch (java.security.AccessControlException e) { |
198 | 198 |
log.append("Access Control Exception.\n"); |
... | ... | |
215 | 215 |
} |
216 | 216 |
|
217 | 217 |
public void disconnect () { |
218 |
try {
|
|
219 |
reader.close();
|
|
220 |
out.close();
|
|
221 |
} catch (IOException e) {
|
|
222 |
}
|
|
218 |
try {
|
|
219 |
reader.close();
|
|
220 |
out.close();
|
|
221 |
} catch (IOException e) {
|
|
222 |
}
|
|
223 | 223 |
} |
224 | 224 |
|
225 | 225 |
/* |
... | ... | |
233 | 233 |
} |
234 | 234 |
//send packet |
235 | 235 |
try { |
236 |
Thread.sleep(50); //pause to be safe
|
|
236 |
Thread.sleep(50); //pause to be safe
|
|
237 | 237 |
out.write(s); |
238 | 238 |
out.flush(); |
239 | 239 |
//log.append("Sent: " + s + "\n"); |
... | ... | |
268 | 268 |
if (robotNumber != null) |
269 | 269 |
packet += " " + robotNumber; |
270 | 270 |
packet += " " + ColonetServerInterface.COLONET_COMMAND; |
271 |
packet += " " + s; //add the command code here
|
|
271 |
packet += " " + s; //add the command code here
|
|
272 | 272 |
packet += "\n"; |
273 | 273 |
sendString(packet); |
274 | 274 |
//txtMatrix.append("S:" + packet); |
... | ... | |
287 | 287 |
String packet = ""; |
288 | 288 |
packet += ColonetServerInterface.REQUEST_FROM_SERVER; |
289 | 289 |
packet += " " + robotNumber; |
290 |
packet += " " + s; //add the command code here
|
|
290 |
packet += " " + s; //add the command code here
|
|
291 | 291 |
packet += "\n"; |
292 | 292 |
sendString(packet); |
293 | 293 |
} |
... | ... | |
332 | 332 |
packet += ColonetServerInterface.SEND_TO_ROBOT; |
333 | 333 |
packet += " " + robotNum; |
334 | 334 |
packet += " " + ColonetServerInterface.COLONET_REQUEST; |
335 |
packet += " " + ColonetServerInterface.BATTERY; //add the command code here
|
|
335 |
packet += " " + ColonetServerInterface.BATTERY; //add the command code here
|
|
336 | 336 |
packet += "\n"; |
337 | 337 |
sendString(packet); |
338 | 338 |
} |
... | ... | |
360 | 360 |
* Order a robot to move to an absolute coordinate point. |
361 | 361 |
*/ |
362 | 362 |
public void sendAbsoluteMove (int id, int x, int y) { |
363 |
sendData(MOVE_TO_ABSOLUTE_POSITION + " " + x + " " + y, "" + id);
|
|
363 |
sendData(MOVE_TO_ABSOLUTE_POSITION + " " + x + " " + y, "" + id);
|
|
364 | 364 |
} |
365 | 365 |
|
366 | 366 |
/* |
367 |
* Queue management
|
|
367 |
* Queue management
|
|
368 | 368 |
*/ |
369 | 369 |
private void sendQueueInstruction (String inst) { |
370 | 370 |
String packet = ""; |
... | ... | |
472 | 472 |
|
473 | 473 |
|
474 | 474 |
/* |
475 |
* DataListener thread.
|
|
475 |
* DataListener thread.
|
|
476 | 476 |
* |
477 | 477 |
*/ |
478 | 478 |
class DataListener extends Thread { |
... | ... | |
487 | 487 |
while (true) { |
488 | 488 |
try { |
489 | 489 |
line = reader.readLine(); |
490 |
if (line == null) |
|
491 |
throw new IOException(); |
|
490 |
if (line == null) { |
|
491 |
throw new IOException(); |
|
492 |
} |
|
492 | 493 |
parseData(line); |
493 | 494 |
Thread.sleep(DATALISTENER_DELAY); |
494 | 495 |
} catch (InterruptedException e) { |
495 | 496 |
return; |
496 | 497 |
} catch (IOException e) { |
497 |
disconnect();
|
|
498 |
colonet.disconnect();
|
|
499 |
return;
|
|
498 |
disconnect();
|
|
499 |
colonet.disconnect();
|
|
500 |
return;
|
|
500 | 501 |
} |
501 | 502 |
} |
502 | 503 |
} |
Also available in: Unified diff