Merge branch 'splitIntoTwoModules' of https://eng-git.canterbury.ac.nz/seng302-2017/team-7 into splitIntoTwoModules
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user