Changed MockInput to thread
#story[778}
This commit is contained in:
@@ -38,15 +38,16 @@ public class Event {
|
|||||||
this.regattaDataSource = regattaData;
|
this.regattaDataSource = regattaData;
|
||||||
try {
|
try {
|
||||||
mockOutput = new MockOutput();
|
mockOutput = new MockOutput();
|
||||||
|
new Thread(mockOutput).start();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
//System.out.println("\nREGATTA DATA\n");//TEMP REMOVE debug
|
System.out.println("\nREGATTA DATA\n");//TEMP REMOVE debug
|
||||||
sendRegattaData();
|
sendRegattaData();
|
||||||
//System.out.println("\nRACE DATA\n");//TEMP REMOVE debug
|
System.out.println("\nRACE DATA\n");//TEMP REMOVE debug
|
||||||
sendRaceData();
|
sendRaceData();
|
||||||
//System.out.println("\nBOAT DATA\n");//TEMP REMOVE debug
|
//System.out.println("\nBOAT DATA\n");//TEMP REMOVE debug
|
||||||
sendBoatData();
|
sendBoatData();
|
||||||
@@ -60,12 +61,10 @@ public class Event {
|
|||||||
|
|
||||||
public void sendRegattaData() throws InvalidRegattaDataException {
|
public void sendRegattaData() throws InvalidRegattaDataException {
|
||||||
|
|
||||||
|
System.setOut(System.out);
|
||||||
RegattaData regattaData = new RegattaData(regattaDataSource);
|
RegattaData regattaData = new RegattaData(regattaDataSource);
|
||||||
String xmlString = regattaData.createXML();
|
String xmlString = regattaData.createXML();
|
||||||
System.out.println("working");
|
|
||||||
mockOutput.parseXMLString(xmlString, 26);
|
mockOutput.parseXMLString(xmlString, 26);
|
||||||
System.out.println("working");
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
package seng302.Networking;
|
package seng302.Networking;
|
||||||
|
import com.sun.xml.internal.bind.v2.runtime.output.SAXOutput;
|
||||||
import seng302.Networking.MessageEncoders.RaceVisionByteEncoder;
|
import seng302.Networking.MessageEncoders.RaceVisionByteEncoder;
|
||||||
import seng302.Networking.MessageEncoders.XMLMessageEncoder;
|
import seng302.Networking.MessageEncoders.XMLMessageEncoder;
|
||||||
import seng302.Networking.Utils.BoatLocationMessage;
|
import seng302.Networking.Utils.BoatLocationMessage;
|
||||||
@@ -11,13 +12,13 @@ import java.util.ArrayList;
|
|||||||
/**
|
/**
|
||||||
* TCP client to recive information from AC35 data source
|
* TCP client to recive information from AC35 data source
|
||||||
*/
|
*/
|
||||||
public class MockOutput
|
public class MockOutput implements Runnable
|
||||||
{
|
{
|
||||||
private long lastHeartbeatTime;
|
private long lastHeartbeatTime;
|
||||||
|
|
||||||
private RaceVisionByteEncoder messageEncoder = new RaceVisionByteEncoder();
|
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 Socket mockSocket;
|
||||||
private DataOutputStream outToVisualiser;
|
private DataOutputStream outToVisualiser;
|
||||||
|
|
||||||
@@ -25,13 +26,12 @@ public class MockOutput
|
|||||||
private ArrayList<byte[]> messagesToSendBuffer = new ArrayList<>();
|
private ArrayList<byte[]> messagesToSendBuffer = new ArrayList<>();
|
||||||
|
|
||||||
private short messageNumber = 1;
|
private short messageNumber = 1;
|
||||||
|
|
||||||
private short xmlSequenceNumber = 1;
|
private short xmlSequenceNumber = 1;
|
||||||
private int heartbeatSequenceNum = 1;
|
private int heartbeatSequenceNum = 1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public MockOutput() throws IOException{
|
public MockOutput() throws IOException {
|
||||||
/*******************************Test********************************/
|
/*******************************Test********************************/
|
||||||
StringBuilder xmlString;
|
StringBuilder xmlString;
|
||||||
|
|
||||||
@@ -40,45 +40,13 @@ public class MockOutput
|
|||||||
|
|
||||||
String line;
|
String line;
|
||||||
xmlString = new StringBuilder();
|
xmlString = new StringBuilder();
|
||||||
while((line=br.readLine())!= null){
|
while ((line = br.readLine()) != null) {
|
||||||
xmlString.append(line.trim());
|
xmlString.append(line.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
parseXMLString(xmlString.toString(), 5);
|
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
|
* calculates the time since last heartbeat
|
||||||
* @return time since last heartbeat
|
* @return time since last heartbeat
|
||||||
@@ -126,6 +94,47 @@ public class MockOutput
|
|||||||
this.messagesToSendBuffer.add(messagesToSendBuffer);
|
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
|
public static void main(String argv[]) throws Exception
|
||||||
{
|
{
|
||||||
MockOutput client = new MockOutput();
|
MockOutput client = new MockOutput();
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class VisualiserInput
|
|||||||
//time since last heartbeat
|
//time since last heartbeat
|
||||||
private long lastHeartbeatTime;
|
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 ServerSocket visualiserSocket;
|
||||||
private Socket connectionSocket;
|
private Socket connectionSocket;
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ public class VisualiserInput
|
|||||||
|
|
||||||
VisualiserInput() throws IOException{
|
VisualiserInput() throws IOException{
|
||||||
|
|
||||||
ServerSocket visualiserSocket = new ServerSocket(4942);
|
ServerSocket visualiserSocket = new ServerSocket(4945);
|
||||||
Socket connectionSocket = visualiserSocket.accept();
|
Socket connectionSocket = visualiserSocket.accept();
|
||||||
|
|
||||||
//this is the test data that streams form the AC35 website
|
//this is the test data that streams form the AC35 website
|
||||||
|
|||||||
Reference in New Issue
Block a user