Merge branch 'splitIntoTwoModules' of https://eng-git.canterbury.ac.nz/seng302-2017/team-7 into splitIntoTwoModules

main
Erika Savell 9 years ago
commit c972dd7caf

@ -0,0 +1,3 @@
<component name="CopyrightManager">
<settings default="" />
</component>

@ -45,6 +45,11 @@
<version>6.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>seng302</groupId>
<artifactId>visualiser</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>

@ -86,4 +86,5 @@ public class XMLMessageDecoder {
InputSource is = new InputSource(new StringReader(xmlMessage));
return is;
}
}

@ -0,0 +1,21 @@
package seng302.Networking.Utils;
/**
* Created by fwy13 on 28/04/17.
*/
public class AC35UnitConverter {
public static double convertGPS(long value){
//converts latitude or longitue to angle
return (double) value * 180.0/21474836418.0;//2^31 = 21474836418
}
public static double convertHeading(long value){
return (double) value * 360.0/65536.0;//2^15
}
public static double convertTrueWindAngle(long value){
return (double) value * 180.0/32768.0;//-2^15 to 2^15
}
}

@ -470,6 +470,19 @@ public class BoatLocationMessage extends AC35Data
this.rudderAngle = rudderAngle;
}
public seng302.GPSCoordinate getGPSLocation(){
seng302.GPSCoordinate coord = new seng302.GPSCoordinate(AC35UnitConverter.convertGPS(latitude), AC35UnitConverter.convertGPS(longitude));
return coord;
}
public double getHeadingDegrees(){
return AC35UnitConverter.convertHeading(getHeading());
}
public double getTrueWindAngleDegrees(){
return AC35UnitConverter.convertTrueWindAngle(getTrueWindAngle());
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();

@ -31,4 +31,8 @@ public class XMLMessage extends AC35Data{
public InputSource getXmlMessage() {
return xmlMessage;
}
public int getXmlMsgSubType() {
return xmlMsgSubType;
}
}

@ -1,13 +1,19 @@
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;
@ -27,18 +33,39 @@ public class VisualiserInput implements Runnable
long heartbeatSeqNum;
private StreamedCourse course = null;
private Map<Integer, BoatLocationMessage> boatLocation;
VisualiserInput() throws IOException{
public VisualiserInput(Socket connectionSocket) throws IOException{
connectionSocket = new Socket(InetAddress.getLocalHost(), 5003);
connectionSocket = new Socket(InetAddress.getLocalHost(), 4942);
//this is the test data that streams form the AC35 website
// connectionSocket = new Socket("livedata.americascup.com",4941);
this.course = new StreamedCourse();
this.boatLocation = new HashMap<>();
this.connectionSocket = connectionSocket;
//start Time
lastHeartbeatTime = System.currentTimeMillis();
this.lastHeartbeatTime = System.currentTimeMillis();
}
/**
* Provides StreamedCourse container for fixed course data
* @return course for current VisualiserInput instance
* @see seng302.Mock.StreamedCourse
*/
public StreamedCourse getCourse() {
return course;
}
/**
* Returns the last boat location message associated with the given boat source ID.
* @param sourceID unique global identifier for boat
* @return most recent location message
*/
public BoatLocationMessage getBoatLocationMessage(int sourceID) {
return boatLocation.get(sourceID);
}
/**
@ -105,7 +132,24 @@ public class VisualiserInput implements Runnable
//no decoder for this.
break;
case XMLMESSAGE:
System.out.println("XML Message!");
// System.out.println("XML Message!");
XMLMessage xml = (XMLMessage) data;
try {
if (xml.getXmlMsgSubType() == xml.XMLTypeRegatta){
System.out.println("Setting Regatta");
course.setRegattaXMLReader(new RegattaXMLReader(xml.getXmlMessage()));
} else if (xml.getXmlMsgSubType() == xml.XMLTypeRace){
System.out.println("Setting Course");
course.setStreamedCourseXMLReader(new StreamedCourseXMLReader(xml.getXmlMessage()));
} else if (xml.getXmlMsgSubType() == xml.XMLTypeBoat){
System.out.println("Setting Boats");
course.setBoatXMLReader(new BoatXMLReader(xml.getXmlMessage()));
}
} catch (SAXException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
break;
case RACESTARTSTATUS:
System.out.println("Race Start Status Message");
@ -123,7 +167,15 @@ public class VisualiserInput implements Runnable
//no decoder
break;
case BOATLOCATION:
System.out.println("Boat Location Message!");
BoatLocationMessage msg = (BoatLocationMessage) data;
if (boatLocation.containsKey(msg.getSourceID())){
if (msg.getTime() > boatLocation.get(msg.getSourceID()).getTime()){
boatLocation.put(msg.getSourceID(), msg);
}
}else{
boatLocation.put(msg.getSourceID(), msg);
}
// System.out.println("Boat Location Message!");
break;
case MARKROUNDING:
// System.out.println("Mark Rounding Message!");
@ -153,8 +205,10 @@ public class VisualiserInput implements Runnable
public static void main(String argv[]) throws Exception
{
VisualiserInput reciever = new VisualiserInput();
reciever.run();
//this is the test data that streams form the AC35 website
Socket socket = new Socket("livedata.americascup.com",4941);
VisualiserInput receiver = new VisualiserInput(socket);
receiver.run();
}
}

@ -4,6 +4,7 @@ import javafx.scene.paint.Color;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import seng302.Model.Boat;
import seng302.XMLReader;
@ -47,6 +48,10 @@ public class BoatXMLReader extends XMLReader {
}
}
public BoatXMLReader(InputSource xmlString) throws IOException, SAXException, ParserConfigurationException {
super(xmlString);
}
public void read() {
readSettings();
readShapes();

@ -2,6 +2,7 @@ package seng302.Mock;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import seng302.XMLReader;
@ -42,6 +43,10 @@ public class RegattaXMLReader extends XMLReader {
}
}
public RegattaXMLReader(InputSource xmlString) throws IOException, SAXException, ParserConfigurationException {
super(xmlString);
}
/**
* Read the XML
*/

@ -15,6 +15,8 @@ public class StreamedCourse implements RaceDataSource {
BoatXMLReader boatXMLReader = null;
RegattaXMLReader regattaXMLReader = null;
public StreamedCourse() {}
public StreamedCourse(StreamedCourseXMLReader streamedCourseXMLReader) {
this.streamedCourseXMLReader = streamedCourseXMLReader;
}
@ -25,15 +27,19 @@ public class StreamedCourse implements RaceDataSource {
public void setBoatXMLReader(BoatXMLReader boatXMLReader) {
this.boatXMLReader = boatXMLReader;
if (streamedCourseXMLReader != null) {
if (streamedCourseXMLReader != null && boatXMLReader != null) {
boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants());
boatXMLReader.read();
}
}
public StreamedCourseXMLReader getStreamedCourseXMLReader() {
return streamedCourseXMLReader;
}
public void setStreamedCourseXMLReader(StreamedCourseXMLReader streamedCourseXMLReader) {
this.streamedCourseXMLReader = streamedCourseXMLReader;
if (streamedCourseXMLReader != null) {
if (streamedCourseXMLReader != null && boatXMLReader != null) {
boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants());
boatXMLReader.read();
}
@ -43,10 +49,6 @@ public class StreamedCourse implements RaceDataSource {
this.regattaXMLReader = regattaXMLReader;
}
public RegattaXMLReader getRegattaXMLReader() {
return regattaXMLReader;
}
public List<Boat> getBoats() {
return boatXMLReader.getBoats();
}

@ -5,6 +5,7 @@ import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import seng302.GPSCoordinate;
import seng302.Model.Leg;
@ -63,6 +64,10 @@ public class StreamedCourseXMLReader extends XMLReader {
}
}
public StreamedCourseXMLReader(InputSource xmlString) throws IOException, SAXException, ParserConfigurationException {
super(xmlString);
}
private void read() throws ParseException, StreamedCourseXMLException {
readRace();
readParticipants();

@ -3,6 +3,7 @@ package seng302;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
@ -26,6 +27,12 @@ public abstract class XMLReader {
doc.getDocumentElement().normalize();
}
public XMLReader(InputSource xmlInput) throws ParserConfigurationException, IOException, SAXException {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
doc = dBuilder.parse(xmlInput);
}
public Document getDocument() {
return doc;
}

Loading…
Cancel
Save