Merge remote-tracking branch 'remotes/origin/splitIntoTwoModules' into NetworkedVisualiser
# Conflicts: # visualiser/src/main/java/seng302/VisualiserInput.java
This commit is contained in:
@@ -30,7 +30,7 @@ public class BoatXMLReader extends XMLReader {
|
||||
* @throws ParserConfigurationException error
|
||||
*/
|
||||
public BoatXMLReader(String filePath) throws IOException, SAXException, ParserConfigurationException, ParseException {
|
||||
this(filePath, false);
|
||||
this(filePath, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,19 +89,14 @@ public class BoatXMLReader extends XMLReader {
|
||||
|
||||
/**
|
||||
* Reads the information about one boat
|
||||
* Ignored values: ShapeID, StoweName, HullNum, Skipper
|
||||
* Ignored values: ShapeID, StoweName, HullNum, Skipper, Type
|
||||
*/
|
||||
private void readSingleBoat(Node boat) {
|
||||
StreamedBoat streamedBoat;
|
||||
String type = "None";
|
||||
int sourceID = -1;
|
||||
String boatName = null;
|
||||
String shortName = null;
|
||||
String country = null;
|
||||
if (exists(boat, "Type")) type = boat.getAttributes().getNamedItem("Type").getTextContent();
|
||||
if (exists(boat, "SourceID")) sourceID = Integer.parseInt(boat.getAttributes().getNamedItem("SourceID").getTextContent());
|
||||
if (exists(boat, "BoatName")) boatName = boat.getAttributes().getNamedItem("BoatName").getTextContent();
|
||||
if (exists(boat, "ShortName")) shortName = boat.getAttributes().getNamedItem("ShortName").getTextContent();
|
||||
int sourceID = Integer.parseInt(boat.getAttributes().getNamedItem("SourceID").getTextContent());
|
||||
String boatName = boat.getAttributes().getNamedItem("BoatName").getTextContent();
|
||||
String shortName = boat.getAttributes().getNamedItem("ShortName").getTextContent();
|
||||
if (exists(boat, "Country")) country = boat.getAttributes().getNamedItem("Country").getTextContent();
|
||||
|
||||
// Ignore all non participating boats
|
||||
@@ -137,10 +132,6 @@ public class BoatXMLReader extends XMLReader {
|
||||
this.participants = participants;
|
||||
}
|
||||
|
||||
public Map<Integer, StreamedBoat> getStreamedBoatMap() {
|
||||
return streamedBoatMap;
|
||||
}
|
||||
|
||||
public List<Boat> getBoats() {
|
||||
return new ArrayList<>(streamedBoatMap.values());
|
||||
}
|
||||
|
||||
@@ -49,4 +49,8 @@ public class StreamedBoat extends Boat {
|
||||
}
|
||||
return azimuth;
|
||||
}
|
||||
|
||||
public int getSourceID() {
|
||||
return sourceID;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
package seng302;
|
||||
package seng302.Networking;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.Mock.*;
|
||||
import seng302.Networking.BinaryMessageDecoder;
|
||||
import seng302.Networking.MessageDecoders.*;
|
||||
import seng302.Networking.Utils.*;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.text.ParseException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static seng302.Networking.Utils.ByteConverter.bytesToInt;
|
||||
import static seng302.Networking.Utils.ByteConverter.bytesToShort;
|
||||
import static seng302.Networking.Utils.MessageType.*;
|
||||
|
||||
/**
|
||||
* TCP server to act as the mock AC35 streaming interface
|
||||
@@ -28,14 +33,16 @@ public class VisualiserInput implements Runnable
|
||||
|
||||
long heartbeatSeqNum;
|
||||
|
||||
private StreamedCourse course;
|
||||
private StreamedCourse course = null;
|
||||
|
||||
private Map<Integer, BoatLocationMessage> boatLocation;
|
||||
|
||||
public VisualiserInput(StreamedCourse course) throws IOException{
|
||||
connectionSocket = new Socket(InetAddress.getLocalHost(), 4942);
|
||||
public VisualiserInput(Socket connectionSocket) throws IOException{
|
||||
|
||||
this.course = course;
|
||||
//connectionSocket = new Socket(InetAddress.getLocalHost(), 4942);
|
||||
this.connectionSocket = connectionSocket;
|
||||
|
||||
this.course = new StreamedCourse();
|
||||
this.boatLocation = new HashMap<>();
|
||||
this.connectionSocket = connectionSocket;
|
||||
|
||||
@@ -80,11 +87,14 @@ public class VisualiserInput implements Runnable
|
||||
*/
|
||||
private static byte[] getBytes(InputStream inStream) throws IOException {
|
||||
byte[] headerBytes = new byte[15];
|
||||
int i = inStream.read(headerBytes);
|
||||
inStream.read(headerBytes);
|
||||
byte[] messageLenBytes = Arrays.copyOfRange(headerBytes, 13, 15);
|
||||
short messageLen = bytesToShort(messageLenBytes);
|
||||
byte[] messageBytesWithCRC = new byte[messageLen+4];
|
||||
int j = inStream.read(messageBytesWithCRC);
|
||||
while (inStream.available() < messageLen + 4){
|
||||
//WE NEED THIS!!!!
|
||||
}
|
||||
inStream.read(messageBytesWithCRC, 0, messageLen + 4);
|
||||
ByteBuffer binaryMessageBytes = ByteBuffer.allocate(headerBytes.length+messageBytesWithCRC.length);
|
||||
binaryMessageBytes.put(headerBytes);
|
||||
binaryMessageBytes.put(messageBytesWithCRC);
|
||||
@@ -200,7 +210,8 @@ public class VisualiserInput implements Runnable
|
||||
public static void main(String argv[]) throws Exception
|
||||
{
|
||||
//this is the test data that streams form the AC35 website
|
||||
VisualiserInput receiver = new VisualiserInput(new StreamedCourse());
|
||||
Socket socket = new Socket("livedata.americascup.com",4941);
|
||||
VisualiserInput receiver = new VisualiserInput(socket);
|
||||
receiver.run();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user