|
|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
package seng302.Networking;
|
|
|
|
|
import com.sun.xml.internal.bind.v2.runtime.output.SAXOutput;
|
|
|
|
|
import seng302.Networking.MessageEncoders.RaceVisionByteEncoder;
|
|
|
|
|
import seng302.Networking.MessageEncoders.XMLMessageEncoder;
|
|
|
|
|
import seng302.Networking.Utils.BoatLocationMessage;
|
|
|
|
|
@ -11,13 +12,13 @@ import java.util.ArrayList;
|
|
|
|
|
/**
|
|
|
|
|
* TCP client to recive information from AC35 data source
|
|
|
|
|
*/
|
|
|
|
|
public class MockOutput
|
|
|
|
|
public class MockOutput implements Runnable
|
|
|
|
|
{
|
|
|
|
|
private long lastHeartbeatTime;
|
|
|
|
|
|
|
|
|
|
private RaceVisionByteEncoder messageEncoder = new RaceVisionByteEncoder();
|
|
|
|
|
|
|
|
|
|
//socket port 4942 as 4940 is ac35 live port and 4941 is ac35 test port
|
|
|
|
|
//socket port 4945 as 4940 is ac35 live port and 4941 is ac35 test port
|
|
|
|
|
private Socket mockSocket;
|
|
|
|
|
private DataOutputStream outToVisualiser;
|
|
|
|
|
|
|
|
|
|
@ -25,13 +26,12 @@ public class MockOutput
|
|
|
|
|
private ArrayList<byte[]> messagesToSendBuffer = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
private short messageNumber = 1;
|
|
|
|
|
|
|
|
|
|
private short xmlSequenceNumber = 1;
|
|
|
|
|
private int heartbeatSequenceNum = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MockOutput() throws IOException{
|
|
|
|
|
public MockOutput() throws IOException {
|
|
|
|
|
/*******************************Test********************************/
|
|
|
|
|
StringBuilder xmlString;
|
|
|
|
|
|
|
|
|
|
@ -40,45 +40,13 @@ public class MockOutput
|
|
|
|
|
|
|
|
|
|
String line;
|
|
|
|
|
xmlString = new StringBuilder();
|
|
|
|
|
while((line=br.readLine())!= null){
|
|
|
|
|
while ((line = br.readLine()) != null) {
|
|
|
|
|
xmlString.append(line.trim());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parseXMLString(xmlString.toString(), 5);
|
|
|
|
|
|
|
|
|
|
/*******************************Test********************************/
|
|
|
|
|
|
|
|
|
|
/**************sockets*******************/
|
|
|
|
|
//start Time
|
|
|
|
|
lastHeartbeatTime = System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mockSocket = new Socket("localhost", 4942);
|
|
|
|
|
outToVisualiser = new DataOutputStream(mockSocket.getOutputStream());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//loop that sends
|
|
|
|
|
while(true)
|
|
|
|
|
{
|
|
|
|
|
//sends a heartbeat every 5 seconds
|
|
|
|
|
if (timeSinceHeartbeat() >= 5.00){
|
|
|
|
|
outToVisualiser.write(heartbeat());
|
|
|
|
|
lastHeartbeatTime = System.currentTimeMillis();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//checks the buffer to see if there is anything to send
|
|
|
|
|
if (messagesToSendBuffer.size() > 0) {
|
|
|
|
|
for (byte[] binaryMessage : messagesToSendBuffer) {
|
|
|
|
|
//sends the message to the visualiser
|
|
|
|
|
outToVisualiser.write(binaryMessage);
|
|
|
|
|
}
|
|
|
|
|
//cleans out buffer
|
|
|
|
|
messagesToSendBuffer.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**************sockets*******************/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* calculates the time since last heartbeat
|
|
|
|
|
* @return time since last heartbeat
|
|
|
|
|
@ -126,6 +94,47 @@ public class MockOutput
|
|
|
|
|
this.messagesToSendBuffer.add(messagesToSendBuffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
/*******************************Test********************************/
|
|
|
|
|
|
|
|
|
|
/**************sockets*******************/
|
|
|
|
|
//start Time
|
|
|
|
|
lastHeartbeatTime = System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mockSocket = new Socket("localhost", 4945);
|
|
|
|
|
outToVisualiser = new DataOutputStream(mockSocket.getOutputStream());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//loop that sends
|
|
|
|
|
while (true) {
|
|
|
|
|
//sends a heartbeat every 5 seconds
|
|
|
|
|
if (timeSinceHeartbeat() >= 5.00) {
|
|
|
|
|
outToVisualiser.write(heartbeat());
|
|
|
|
|
lastHeartbeatTime = System.currentTimeMillis();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//checks the buffer to see if there is anything to send
|
|
|
|
|
if (messagesToSendBuffer.size() > 0) {
|
|
|
|
|
for (byte[] binaryMessage : messagesToSendBuffer) {
|
|
|
|
|
//sends the message to the visualiser
|
|
|
|
|
outToVisualiser.write(binaryMessage);
|
|
|
|
|
}
|
|
|
|
|
//cleans out buffer
|
|
|
|
|
messagesToSendBuffer.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**************sockets*******************/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String argv[]) throws Exception
|
|
|
|
|
{
|
|
|
|
|
MockOutput client = new MockOutput();
|
|
|
|
|
|