blob: 897371da6f84f69a24582f0f3cd64e9b56cf09e2 [file] [log] [blame]
danielp64c4e052013-02-23 07:21:41 +00001/**
2 *
3 */
4package org.frc971;
5
6import java.io.IOException;
7
8import java.net.InetSocketAddress;
9
10import java.nio.channels.ServerSocketChannel;
11
12/**
13 * @author daniel
14 *
15 */
16
17/** Serves processing results back to the atom. */
18public class ResultSender {
19 private static final int PORT = 9715;
20
21 private ServerSocketChannel sock;
22
23 AccepterThread acceptor;
24
25 /** Constructor. Connects to a socket and starts the accepter thread. */
26 public ResultSender() throws IOException {
27 sock = ServerSocketChannel.open();
28 sock.socket().bind(new InetSocketAddress(PORT));
29
30 //start accepter thread
31 acceptor = new AccepterThread(sock);
32 }
33
34 /** Sends a new message of calculated attributes to the clients.
35 *
36 * @param azimuth is the calculated optimum azimuth for the shot.
37 * @param elevation is the calculated optimum elevation for the shot.
38 * @param range is the calculated optimum range for the shot.
39 */
40 public void send(double azimuth, double elevation, double range) {
41 //Formulate a message as a String similar to an HTTP header.
42 StringBuilder message = new StringBuilder();
43 message.append("\r\n--boundarydonotcross\r\n");
44 message.append("Azimuth: ");
45 message.append(azimuth);
46 message.append("\r\nElevation: ");
47 message.append(elevation);
48 message.append("\r\nRange: ");
49 message.append(range);
50
51 acceptor.sendtoAll(message.toString());
52 }
53}