Merge branch 'splitIntoTwoModules' of https://eng-git.canterbury.ac.nz/seng302-2017/team-7 into splitIntoTwoModules
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package seng302.Networking;
|
||||
|
||||
import seng302.Networking.MessageEncoders.RaceVisionByteEncoder;
|
||||
import seng302.Networking.MessageEncoders.XMLMessageEncoder;
|
||||
import seng302.Networking.Utils.BoatLocationMessage;
|
||||
import seng302.Networking.Utils.MessageType;
|
||||
|
||||
import java.io.*;
|
||||
@@ -11,13 +11,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
|
||||
private ServerSocket serverSocket;
|
||||
private Socket mockSocket;
|
||||
private DataOutputStream outToVisualiser;
|
||||
|
||||
@@ -25,60 +25,19 @@ public class MockOutput
|
||||
private ArrayList<byte[]> messagesToSendBuffer = new ArrayList<>();
|
||||
|
||||
private short messageNumber = 1;
|
||||
|
||||
private short xmlSequenceNumber = 1;
|
||||
private int heartbeatSequenceNum = 1;
|
||||
|
||||
|
||||
|
||||
MockOutput() throws IOException{
|
||||
/*******************************Test********************************/
|
||||
StringBuilder xmlString;
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(
|
||||
this.getClass().getResourceAsStream(("/raceXML/Regatta.xml"))));
|
||||
|
||||
String line;
|
||||
xmlString = new StringBuilder();
|
||||
while((line=br.readLine())!= null){
|
||||
xmlString.append(line.trim());
|
||||
}
|
||||
|
||||
parseXMLString(xmlString.toString(), 5);
|
||||
|
||||
/*******************************Test********************************/
|
||||
|
||||
/**************sockets*******************/
|
||||
public MockOutput() throws IOException {
|
||||
/**************sockets*******************/
|
||||
//start Time
|
||||
lastHeartbeatTime = System.currentTimeMillis();
|
||||
|
||||
|
||||
mockSocket = new Socket("localhost", 4942);
|
||||
outToVisualiser = new DataOutputStream(mockSocket.getOutputStream());
|
||||
serverSocket = new ServerSocket(4942);
|
||||
|
||||
|
||||
//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 +85,61 @@ public class MockOutput
|
||||
this.messagesToSendBuffer.add(messagesToSendBuffer);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
while (true){
|
||||
mockSocket = serverSocket.accept();
|
||||
outToVisualiser = new DataOutputStream(mockSocket.getOutputStream());
|
||||
|
||||
/*******************************Test********************************/
|
||||
StringBuilder xmlString;
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(
|
||||
this.getClass().getResourceAsStream(("/raceXML/Regatta.xml"))));
|
||||
|
||||
String line;
|
||||
xmlString = new StringBuilder();
|
||||
while((line=br.readLine())!= null){
|
||||
xmlString.append(line.trim());
|
||||
}
|
||||
|
||||
parseXMLString(xmlString.toString(), 5);
|
||||
|
||||
/*******************************Test********************************/
|
||||
|
||||
while(true) {
|
||||
try {
|
||||
//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(SocketException e){
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} 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,12 +32,10 @@ public class VisualiserInput
|
||||
|
||||
VisualiserInput() throws IOException{
|
||||
|
||||
//sockets to connect to
|
||||
// ServerSocket visualiserSocket = new ServerSocket(4942);
|
||||
// Socket connectionSocket = visualiserSocket.accept();
|
||||
Socket connectionSocket = new Socket(InetAddress.getLocalHost(), 4942);
|
||||
|
||||
//this is the test data that streams form the AC35 website
|
||||
Socket connectionSocket = new Socket("livedata.americascup.com",4941);
|
||||
// Socket connectionSocket = new Socket("livedata.americascup.com",4941);
|
||||
|
||||
|
||||
//start Time
|
||||
|
||||
Reference in New Issue
Block a user