Fixed up code, made it prettier, it now follows the stylguide better and is more readable.
git-svn-id: https://robotics.mvla.net/svn/frc971/2013/trunk/src@4182 f308d9b7-e957-4cde-b6ac-9a88185e7312
diff --git a/971cv/src/org/spartanrobotics/ResultSender.java b/971cv/src/org/spartanrobotics/ResultSender.java
new file mode 100644
index 0000000..14d69a1
--- /dev/null
+++ b/971cv/src/org/spartanrobotics/ResultSender.java
@@ -0,0 +1,55 @@
+/**
+ *
+ */
+package org.spartanrobotics;
+
+import java.io.IOException;
+
+import java.net.InetSocketAddress;
+
+import java.nio.channels.ServerSocketChannel;
+
+/**
+ * @author daniel
+ *
+ */
+
+/** Serves processing results back to the atom. */
+public class ResultSender {
+ private static final int PORT = 9716;
+
+ private ServerSocketChannel sock;
+
+ AccepterThread acceptor;
+
+ /** Constructor. Connects to a socket and starts the accepter thread. */
+ public ResultSender() throws IOException {
+ sock = ServerSocketChannel.open();
+ sock.socket().bind(new InetSocketAddress(PORT));
+
+ //start accepter thread
+ acceptor = new AccepterThread(sock);
+ }
+
+ /** Sends a new message of calculated attributes to the clients.
+ *
+ * @param azimuth is the calculated optimum azimuth for the shot.
+ * @param elevation is the calculated optimum elevation for the shot.
+ * @param range is the calculated optimum range for the shot.
+ */
+ public void send(double azimuth, double elevation, double range) {
+ //Formulate a message as a String similar to an HTTP header.
+ if (azimuth != 0.0d && elevation != 0.0d && range != 0.0d) {
+ StringBuilder message = new StringBuilder();
+ message.append("\r\n--boundarydonotcross\r\n");
+ message.append("Azimuth: ");
+ message.append(azimuth);
+ message.append("\r\nElevation: ");
+ message.append(elevation);
+ message.append("\r\nRange: ");
+ message.append(range);
+
+ acceptor.sendtoAll(message.toString());
+ }
+ }
+}