Changed MockInput to thread
#story[778}
This commit is contained in:
@@ -38,15 +38,16 @@ public class Event {
|
||||
this.regattaDataSource = regattaData;
|
||||
try {
|
||||
mockOutput = new MockOutput();
|
||||
new Thread(mockOutput).start();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
//System.out.println("\nREGATTA DATA\n");//TEMP REMOVE debug
|
||||
System.out.println("\nREGATTA DATA\n");//TEMP REMOVE debug
|
||||
sendRegattaData();
|
||||
//System.out.println("\nRACE DATA\n");//TEMP REMOVE debug
|
||||
System.out.println("\nRACE DATA\n");//TEMP REMOVE debug
|
||||
sendRaceData();
|
||||
//System.out.println("\nBOAT DATA\n");//TEMP REMOVE debug
|
||||
sendBoatData();
|
||||
@@ -60,12 +61,10 @@ public class Event {
|
||||
|
||||
public void sendRegattaData() throws InvalidRegattaDataException {
|
||||
|
||||
System.setOut(System.out);
|
||||
RegattaData regattaData = new RegattaData(regattaDataSource);
|
||||
String xmlString = regattaData.createXML();
|
||||
System.out.println("working");
|
||||
mockOutput.parseXMLString(xmlString, 26);
|
||||
System.out.println("working");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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,7 +26,6 @@ public class MockOutput
|
||||
private ArrayList<byte[]> messagesToSendBuffer = new ArrayList<>();
|
||||
|
||||
private short messageNumber = 1;
|
||||
|
||||
private short xmlSequenceNumber = 1;
|
||||
private int heartbeatSequenceNum = 1;
|
||||
|
||||
@@ -46,39 +46,7 @@ public class MockOutput
|
||||
|
||||
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();
|
||||
|
||||
@@ -22,7 +22,7 @@ public class VisualiserInput
|
||||
//time since last heartbeat
|
||||
private long lastHeartbeatTime;
|
||||
|
||||
//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 ServerSocket visualiserSocket;
|
||||
private Socket connectionSocket;
|
||||
|
||||
@@ -32,7 +32,7 @@ public class VisualiserInput
|
||||
|
||||
VisualiserInput() throws IOException{
|
||||
|
||||
ServerSocket visualiserSocket = new ServerSocket(4942);
|
||||
ServerSocket visualiserSocket = new ServerSocket(4945);
|
||||
Socket connectionSocket = visualiserSocket.accept();
|
||||
|
||||
//this is the test data that streams form the AC35 website
|
||||
|
||||
Reference in New Issue
Block a user