Merged Mock49 and fixed bugs

- Error where mock would not read in the files when running from the jar.
- Error where the AC35 stream now no longer sends us packets with information that is set for 0 for boat location.
#story[881] #pair[fwy13, esa46
main
Fan-Wu Yang 9 years ago
parent 7bfb6bb968
commit b065b8d9c7

@ -4,12 +4,25 @@ package seng302;
import javafx.application.Application; import javafx.application.Application;
import javafx.stage.Stage; import javafx.stage.Stage;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import seng302.DataInput.XMLReader;
import seng302.Model.Event; import seng302.Model.Event;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
public class App extends Application { public class App extends Application {
@ -27,21 +40,35 @@ public class App extends Application {
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
try { try {
String regattaXML = readFile("mock/src/main/resources/mockXML/regattaTest.xml", StandardCharsets.UTF_8); String regattaXML = readFile("mockXML/regattaTest.xml", StandardCharsets.UTF_8);
String raceXML = readFile("mock/src/main/resources/mockXML/raceTest.xml", StandardCharsets.UTF_8); String raceXML = readFile("mockXML/raceTest.xml", StandardCharsets.UTF_8);
String boatXML = readFile("mock/src/main/resources/mockXML/boatTest.xml", StandardCharsets.UTF_8); String boatXML = readFile("mockXML/boatTest.xml", StandardCharsets.UTF_8);
Event raceEvent = new Event(raceXML, regattaXML, boatXML); Event raceEvent = new Event(raceXML, regattaXML, boatXML);
raceEvent.start(); raceEvent.start();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (TransformerException e) {
e.printStackTrace();
} }
} }
static String readFile(String path, Charset encoding) throws IOException { private String readFile(String path, Charset encoding) throws IOException, ParserConfigurationException, SAXException, TransformerException {
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding); InputSource fXmlFile = new InputSource(getClass().getClassLoader().getResourceAsStream(path));
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
return XMLReader.getContents(doc);
} }
} }

@ -9,9 +9,13 @@ import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter;
/** /**
* Created by fwy13 on 26/03/2017. * Created by fwy13 on 26/03/2017.
@ -80,4 +84,19 @@ public abstract class XMLReader {
return node.getAttributes().getNamedItem(attribute) != null; return node.getAttributes().getNamedItem(attribute) != null;
} }
public static String getContents(Document document) throws TransformerException {
DOMSource source = new DOMSource(document);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
StringWriter stringWriter = new StringWriter();
StreamResult result = new StreamResult(stringWriter);
transformer.transform(source, result);
return stringWriter.toString();
}
} }

@ -226,7 +226,6 @@ public class Race implements Runnable {
//distanceTravelled = velocity (nm p hr) * time taken to update loop //distanceTravelled = velocity (nm p hr) * time taken to update loop
double distanceTravelled = (boat.getScaledVelocity() * millisecondsElapsed) / 3600000; double distanceTravelled = (boat.getScaledVelocity() * millisecondsElapsed) / 3600000;
double totalDistanceTravelled = distanceTravelled + boat.getDistanceTravelledInLeg(); double totalDistanceTravelled = distanceTravelled + boat.getDistanceTravelledInLeg();
System.out.println(totalDistanceTravelled);
boolean finish = boat.getCurrentLeg().getName().equals("Finish"); boolean finish = boat.getCurrentLeg().getName().equals("Finish");
if (!finish) { if (!finish) {

@ -36,44 +36,100 @@ public class BoatLocationDecoder {
private BoatLocation message; private BoatLocation message;
public BoatLocationDecoder(byte[] encodedBoatLocation) { public BoatLocationDecoder(byte[] encodedBoatLocation) {
messageVersionNumber = encodedBoatLocation[0]; byte numMessageVersionNumber = 0;
time = Arrays.copyOfRange(encodedBoatLocation, 1, 7); long numTime = 0;
sourceID = Arrays.copyOfRange(encodedBoatLocation, 7, 11); int numSourceID = 0;
seqNum = Arrays.copyOfRange(encodedBoatLocation, 11, 15); int numSeqNum = 0;
deviceType = encodedBoatLocation[15]; byte numDeviceType = 0;
latitude = Arrays.copyOfRange(encodedBoatLocation, 16, 20); int numLatitude = 0;
longitude = Arrays.copyOfRange(encodedBoatLocation,20, 24); int numLongitude = 0;
altitude = Arrays.copyOfRange(encodedBoatLocation, 24, 28); int numAltitude = 0;
heading = Arrays.copyOfRange(encodedBoatLocation,28, 30); int numHeading = 0;
pitch =Arrays.copyOfRange(encodedBoatLocation,30,32); short numPitch = 0;
roll = Arrays.copyOfRange(encodedBoatLocation,32,34); short numRoll = 0;
boatSpeed = Arrays.copyOfRange(encodedBoatLocation,34,36); int numBoatSpeed = 0;
cog = Arrays.copyOfRange(encodedBoatLocation,36,38); int numCog = 0;
sog = Arrays.copyOfRange(encodedBoatLocation,38, 40); int numSog = 0;
apparentWindSpeed = Arrays.copyOfRange(encodedBoatLocation, 40, 42); int numApparentWindSpeed = 0;
apparentWindAngle = Arrays.copyOfRange(encodedBoatLocation, 42, 44); short numApparentWindAngle = 0;
trueWindSpeed = Arrays.copyOfRange(encodedBoatLocation,44, 46); int numTrueWindSpeed = 0;
trueWindDirection = Arrays.copyOfRange(encodedBoatLocation, 46, 48); short numTrueWindDirection = 0;
trueWindAngle = Arrays.copyOfRange(encodedBoatLocation, 48, 50); short numTrueWindAngle = 0;
currentDrift = Arrays.copyOfRange(encodedBoatLocation,50,52); int numCurrentDrift = 0;
currentSet = Arrays.copyOfRange(encodedBoatLocation,52, 54); int numCurrentSet = 0;
rudderAngle = Arrays.copyOfRange(encodedBoatLocation,54, 56); short numRudderAngle = 0;
// System.out.println(bytesToInt(sourceID)); try {
// System.out.println(bytesToInt(boatSpeed)); messageVersionNumber = encodedBoatLocation[0];
numMessageVersionNumber = messageVersionNumber;
time = Arrays.copyOfRange(encodedBoatLocation, 1, 7);
numTime = bytesToLong(time);
sourceID = Arrays.copyOfRange(encodedBoatLocation, 7, 11);
numSourceID = bytesToInt(sourceID);
seqNum = Arrays.copyOfRange(encodedBoatLocation, 11, 15);
numSeqNum = bytesToInt(seqNum);
deviceType = encodedBoatLocation[15];
numDeviceType = deviceType;
latitude = Arrays.copyOfRange(encodedBoatLocation, 16, 20);
numLatitude = bytesToInt(latitude);
longitude = Arrays.copyOfRange(encodedBoatLocation, 20, 24);
numLongitude = bytesToInt(longitude);
altitude = Arrays.copyOfRange(encodedBoatLocation, 24, 28);
numAltitude = bytesToInt(altitude);
heading = Arrays.copyOfRange(encodedBoatLocation, 28, 30);
numHeading = bytesToInt(heading);
pitch = Arrays.copyOfRange(encodedBoatLocation, 30, 32);
numPitch = bytesToShort(pitch);
roll = Arrays.copyOfRange(encodedBoatLocation, 32, 34);
numRoll = bytesToShort(roll);
boatSpeed = Arrays.copyOfRange(encodedBoatLocation, 34, 36);
numBoatSpeed = bytesToInt(boatSpeed);
cog = Arrays.copyOfRange(encodedBoatLocation, 36, 38);
numCog = bytesToInt(cog);
sog = Arrays.copyOfRange(encodedBoatLocation, 38, 40);
numSog = bytesToInt(sog);
apparentWindSpeed = Arrays.copyOfRange(encodedBoatLocation, 40, 42);
numApparentWindSpeed = bytesToInt(apparentWindSpeed);
apparentWindAngle = Arrays.copyOfRange(encodedBoatLocation, 42, 44);
numApparentWindAngle = bytesToShort(apparentWindAngle);
trueWindSpeed = Arrays.copyOfRange(encodedBoatLocation, 44, 46);
numTrueWindSpeed = bytesToInt(trueWindSpeed);
trueWindDirection = Arrays.copyOfRange(encodedBoatLocation, 46, 48);
numTrueWindDirection = bytesToShort(trueWindSpeed);
trueWindAngle = Arrays.copyOfRange(encodedBoatLocation, 48, 50);
numTrueWindAngle = bytesToShort(trueWindSpeed);
currentDrift = Arrays.copyOfRange(encodedBoatLocation, 50, 52);
numCurrentDrift = bytesToInt(currentDrift);
currentSet = Arrays.copyOfRange(encodedBoatLocation, 52, 54);
numCurrentSet = bytesToShort(currentSet);
rudderAngle = Arrays.copyOfRange(encodedBoatLocation, 54, 56);
numRudderAngle = bytesToShort(rudderAngle);
} catch(ArrayIndexOutOfBoundsException e){
}
message = new BoatLocation(numMessageVersionNumber, numTime,
numSourceID, numSeqNum, numDeviceType, numLatitude,
numLongitude, numAltitude, numHeading, numPitch,
numRoll, numBoatSpeed, numCog, numSog, numApparentWindSpeed,
numApparentWindAngle, numTrueWindSpeed, numTrueWindDirection,
numTrueWindAngle, numCurrentDrift, numCurrentSet, numRudderAngle
);/*
message = new BoatLocation(messageVersionNumber, bytesToLong(time), message = new BoatLocation(messageVersionNumber, bytesToLong(time),
bytesToInt(sourceID), bytesToInt(seqNum), bytesToInt(sourceID), bytesToInt(seqNum),
deviceType, bytesToInt(latitude), deviceType, bytesToInt(latitude),
bytesToInt(longitude), bytesToInt(altitude), bytesToInt(longitude), bytesToInt(altitude),
bytesToInt(heading), bytesToShort(pitch), bytesToInt(heading), bytesToShort(pitch),
bytesToShort(roll), bytesToInt(boatSpeed), bytesToShort(roll), bytesToInt(boatSpeed),
bytesToInt(cog), bytesToInt(sog), bytesToInt(cog), bytesToInt(sog),
bytesToInt(apparentWindSpeed), bytesToShort(apparentWindAngle), bytesToInt(apparentWindSpeed), bytesToShort(apparentWindAngle),
bytesToInt(trueWindSpeed), bytesToShort(trueWindDirection), bytesToInt(trueWindSpeed), bytesToShort(trueWindDirection),
bytesToShort(trueWindAngle), bytesToInt(currentDrift), bytesToShort(trueWindAngle), bytesToInt(currentDrift),
bytesToInt(currentSet), bytesToShort(rudderAngle) bytesToInt(currentSet), bytesToShort(rudderAngle)
); );*/
// System.out.println(bytesToInt(sourceID));
// System.out.println(bytesToInt(boatSpeed));
} }

@ -46,7 +46,7 @@ public class RaceStatus extends AC35Data {
} }
/** /**
* @deprecated use status booleans *
* @return race status number * @return race status number
*/ */
public int getRaceStatus() public int getRaceStatus()

@ -25,7 +25,6 @@ public class StreamedCourse extends Observable implements RaceDataSource {
this.boatXMLReader = boatXMLReader; this.boatXMLReader = boatXMLReader;
if (streamedCourseXMLReader != null && boatXMLReader != null) { if (streamedCourseXMLReader != null && boatXMLReader != null) {
this.boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants()); this.boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants());
System.out.println(streamedCourseXMLReader.getParticipants().size());
boatXMLReader.read(); boatXMLReader.read();
} }

@ -30,7 +30,7 @@ public class Marker {
} }
/** /**
* @deprecated *
* @param mark1 Mark coordinates. * @param mark1 Mark coordinates.
*/ */
public Marker(GPSCoordinate mark1) { public Marker(GPSCoordinate mark1) {
@ -38,7 +38,7 @@ public class Marker {
} }
/** /**
* @deprecated *
* @param mark1 Mark one coordinate * @param mark1 Mark one coordinate
* @param mark2 Mark two coordinate * @param mark2 Mark two coordinate
*/ */

@ -159,7 +159,7 @@ public class VisualiserInput implements Runnable {
* @throws IOException Thrown when an error occurs while reading from the socket. * @throws IOException Thrown when an error occurs while reading from the socket.
*/ */
private byte[] getNextMessageBytes() throws IOException { private byte[] getNextMessageBytes() throws IOException {
inStream.mark(0);
short CRCLength = 4; short CRCLength = 4;
short headerLength = 15; short headerLength = 15;
@ -253,6 +253,11 @@ public class VisualiserInput implements Runnable {
catch (InvalidMessageException | IOException e) { catch (InvalidMessageException | IOException e) {
//Prints exception to stderr, and iterate loop (that is, read the next message). //Prints exception to stderr, and iterate loop (that is, read the next message).
System.err.println("Unable to read message: " + e.getMessage()); System.err.println("Unable to read message: " + e.getMessage());
try {
inStream.reset();
} catch (IOException e1) {
e1.printStackTrace();
}
//Continue to the next loop iteration/message. //Continue to the next loop iteration/message.
continue; continue;
}/* }/*

Loading…
Cancel
Save