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:
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,4 +31,8 @@ public class XMLMessage extends AC35Data{
|
||||
public InputSource getXmlMessage() {
|
||||
return xmlMessage;
|
||||
}
|
||||
|
||||
public int getXmlMsgSubType() {
|
||||
return xmlMsgSubType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
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.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.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static seng302.Networking.Utils.ByteConverter.bytesToInt;
|
||||
@@ -27,12 +34,17 @@ public class VisualiserInput implements Runnable
|
||||
|
||||
long heartbeatSeqNum;
|
||||
|
||||
private Map<Integer, BoatLocationMessage> boatLocation;
|
||||
private BoatXMLReader boatXMLReader;
|
||||
private StreamedCourseXMLReader streamedCourseXMLReader;
|
||||
private RegattaXMLReader regattaXMLReader;
|
||||
|
||||
|
||||
VisualiserInput() throws IOException{
|
||||
|
||||
// connectionSocket = new Socket(InetAddress.getLocalHost(), 4942);
|
||||
|
||||
boatLocation = new HashMap<>();
|
||||
//this is the test data that streams form the AC35 website
|
||||
connectionSocket = new Socket("livedata.americascup.com",4941);
|
||||
|
||||
@@ -106,6 +118,20 @@ public class VisualiserInput implements Runnable
|
||||
break;
|
||||
case XMLMESSAGE:
|
||||
// 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());
|
||||
break;
|
||||
case RACESTARTSTATUS:
|
||||
@@ -124,6 +150,14 @@ public class VisualiserInput implements Runnable
|
||||
//no decoder
|
||||
break;
|
||||
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!");
|
||||
break;
|
||||
case MARKROUNDING:
|
||||
|
||||
Reference in New Issue
Block a user