Added a few decoders and unit converters
- Units can be converted from int to degrees as a double - XML message now keeps the most recent XML file #story[782]
This commit is contained in:
@@ -214,7 +214,7 @@ public class Race implements Runnable {
|
|||||||
|
|
||||||
//We have finished creating the message.
|
//We have finished creating the message.
|
||||||
|
|
||||||
mockOutput.parseBoatLocation();
|
mockOutput.parseBoatLocation(boat);
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -45,6 +45,11 @@
|
|||||||
<version>6.11</version>
|
<version>6.11</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>seng302</groupId>
|
||||||
|
<artifactId>visualiser</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -86,4 +86,5 @@ public class XMLMessageDecoder {
|
|||||||
InputSource is = new InputSource(new StringReader(xmlMessage));
|
InputSource is = new InputSource(new StringReader(xmlMessage));
|
||||||
return is;
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -31,4 +31,8 @@ public class XMLMessage extends AC35Data{
|
|||||||
public InputSource getXmlMessage() {
|
public InputSource getXmlMessage() {
|
||||||
return xmlMessage;
|
return xmlMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getXmlMsgSubType() {
|
||||||
|
return xmlMsgSubType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
package seng302.Networking;
|
package seng302.Networking;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
import seng302.Mock.BoatXMLReader;
|
||||||
|
import seng302.Mock.RegattaXMLReader;
|
||||||
|
import seng302.Mock.StreamedCourseXMLReader;
|
||||||
import seng302.Networking.BinaryMessageDecoder;
|
import seng302.Networking.BinaryMessageDecoder;
|
||||||
import seng302.Networking.MessageDecoders.*;
|
import seng302.Networking.MessageDecoders.*;
|
||||||
import seng302.Networking.Utils.*;
|
import seng302.Networking.Utils.*;
|
||||||
|
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static seng302.Networking.Utils.ByteConverter.bytesToInt;
|
import static seng302.Networking.Utils.ByteConverter.bytesToInt;
|
||||||
@@ -27,12 +34,17 @@ public class VisualiserInput implements Runnable
|
|||||||
|
|
||||||
long heartbeatSeqNum;
|
long heartbeatSeqNum;
|
||||||
|
|
||||||
|
private Map<Integer, BoatLocationMessage> boatLocation;
|
||||||
|
private BoatXMLReader boatXMLReader;
|
||||||
|
private StreamedCourseXMLReader streamedCourseXMLReader;
|
||||||
|
private RegattaXMLReader regattaXMLReader;
|
||||||
|
|
||||||
|
|
||||||
VisualiserInput() throws IOException{
|
VisualiserInput() throws IOException{
|
||||||
|
|
||||||
// connectionSocket = new Socket(InetAddress.getLocalHost(), 4942);
|
// connectionSocket = new Socket(InetAddress.getLocalHost(), 4942);
|
||||||
|
|
||||||
|
boatLocation = new HashMap<>();
|
||||||
//this is the test data that streams form the AC35 website
|
//this is the test data that streams form the AC35 website
|
||||||
connectionSocket = new Socket("livedata.americascup.com",4941);
|
connectionSocket = new Socket("livedata.americascup.com",4941);
|
||||||
|
|
||||||
@@ -106,6 +118,20 @@ public class VisualiserInput implements Runnable
|
|||||||
break;
|
break;
|
||||||
case XMLMESSAGE:
|
case XMLMESSAGE:
|
||||||
// System.out.println("XML Message!");
|
// System.out.println("XML Message!");
|
||||||
|
XMLMessage xml = (XMLMessage) data;/*
|
||||||
|
try {
|
||||||
|
if (xml.getXmlMsgSubType() == xml.XMLTypeRegatta){
|
||||||
|
regattaXMLReader = new RegattaXMLReader(xml.getXmlMessage());
|
||||||
|
} else if (xml.getXmlMsgSubType() == xml.XMLTypeRace){
|
||||||
|
streamedCourseXMLReader = new StreamedCourseXMLReader(xml.getXmlMessage());
|
||||||
|
} else if (xml.getXmlMsgSubType() == xml.XMLTypeBoat){
|
||||||
|
boatXMLReader = new BoatXMLReader(xml.getXmlMessage());
|
||||||
|
}
|
||||||
|
} catch (SAXException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ParserConfigurationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}*/
|
||||||
System.out.println(((XMLMessage)data).getXmlMessage());
|
System.out.println(((XMLMessage)data).getXmlMessage());
|
||||||
break;
|
break;
|
||||||
case RACESTARTSTATUS:
|
case RACESTARTSTATUS:
|
||||||
@@ -124,6 +150,14 @@ public class VisualiserInput implements Runnable
|
|||||||
//no decoder
|
//no decoder
|
||||||
break;
|
break;
|
||||||
case BOATLOCATION:
|
case BOATLOCATION:
|
||||||
|
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!");
|
// System.out.println("Boat Location Message!");
|
||||||
break;
|
break;
|
||||||
case MARKROUNDING:
|
case MARKROUNDING:
|
||||||
|
|||||||
Reference in New Issue
Block a user