mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Merge branch 'develop' of https://eng-git.canterbury.ac.nz/seng302-2017/team-13 into develop
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package seng302;
|
package seng302;
|
||||||
|
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.application.Platform;
|
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
@@ -20,8 +19,9 @@ public class App extends Application
|
|||||||
primaryStage.setMaximized(true);
|
primaryStage.setMaximized(true);
|
||||||
|
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
|
|
||||||
primaryStage.setOnCloseRequest(e -> {
|
primaryStage.setOnCloseRequest(e -> {
|
||||||
Platform.exit();
|
System.exit(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package seng302.models.parsers;
|
package seng302.models.parsers;
|
||||||
|
|
||||||
|
|
||||||
import javafx.geometry.Point3D;
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
@@ -12,7 +11,6 @@ import seng302.models.parsers.packets.StreamPacket;
|
|||||||
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 java.io.ByteArrayInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
@@ -110,6 +108,7 @@ public class StreamParser extends Thread{
|
|||||||
* @param packet the packet to be looked at
|
* @param packet the packet to be looked at
|
||||||
*/
|
*/
|
||||||
private static void parsePacket(StreamPacket packet) {
|
private static void parsePacket(StreamPacket packet) {
|
||||||
|
try{
|
||||||
switch (packet.getType()){
|
switch (packet.getType()){
|
||||||
case HEARTBEAT:
|
case HEARTBEAT:
|
||||||
extractHeartBeat(packet);
|
extractHeartBeat(packet);
|
||||||
@@ -152,6 +151,10 @@ public class StreamParser extends Thread{
|
|||||||
//System.out.println(packet.getType().toString());
|
//System.out.println(packet.getType().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (NullPointerException e){
|
||||||
|
System.out.println("Error parsing packet");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts the seq num used in the heartbeat packet
|
* Extracts the seq num used in the heartbeat packet
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public class ServerThread implements Runnable, Observer {
|
|||||||
thereAreBoatsNotFinished = true;
|
thereAreBoatsNotFinished = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
BoatSubMessage m = new BoatSubMessage(b.getSourceID(), boatStatus, b.getLastPassedCorner().getSeqID(), 0, 0, 0, 0);
|
BoatSubMessage m = new BoatSubMessage(b.getSourceID(), boatStatus, b.getLastPassedCorner().getSeqID(), 0, 0, b.getEstimatedTimeTillFinish(), b.getEstimatedTimeTillFinish());
|
||||||
boatSubMessages.add(m);
|
boatSubMessages.add(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package seng302.server.messages;
|
package seng302.server.messages;
|
||||||
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,6 +15,8 @@ public class BoatSubMessage{
|
|||||||
private long numberPenaltiesServed;
|
private long numberPenaltiesServed;
|
||||||
private long estimatedTimeAtNextMark;
|
private long estimatedTimeAtNextMark;
|
||||||
private long estimatedTimeAtFinish;
|
private long estimatedTimeAtFinish;
|
||||||
|
private ByteBuffer buff = ByteBuffer.allocate(getSize());
|
||||||
|
private int buffPos = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boat Sub message from section 4.2 of the AC35 streaming data interface spec
|
* Boat Sub message from section 4.2 of the AC35 streaming data interface spec
|
||||||
@@ -45,47 +46,39 @@ public class BoatSubMessage{
|
|||||||
return MESSAGE_SIZE;
|
return MESSAGE_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void putInBuffer(byte[] bytes, long val){
|
||||||
|
byte[] tmp = bytes.clone();
|
||||||
|
Message.reverse(tmp);
|
||||||
|
|
||||||
|
buff.put(tmp);
|
||||||
|
buffPos += tmp.length;
|
||||||
|
buff.position(buffPos);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a ByteBuffer containing this boat status message
|
* @return a ByteBuffer containing this boat status message
|
||||||
*/
|
*/
|
||||||
public ByteBuffer getByteBuffer(){
|
public ByteBuffer getByteBuffer(){
|
||||||
ByteBuffer buff = ByteBuffer.allocate(getSize());
|
|
||||||
int buffPos = 0;
|
|
||||||
|
|
||||||
// Source ID, 4 bytes
|
// Source ID, 4 bytes
|
||||||
buff.put(ByteBuffer.allocate(4).putInt((int) sourceId).array());
|
putInBuffer(Message.intToByteArray(sourceId, 4), 4);
|
||||||
buffPos += 4;
|
|
||||||
buff.position(buffPos);
|
|
||||||
|
|
||||||
// Boat Status, 1 byte
|
// Boat Status, 1 byte
|
||||||
buff.put(ByteBuffer.allocate(1).put((byte) (boatStatus.getCode() & 0xff)).array());
|
putInBuffer(ByteBuffer.allocate(1).put((byte) (boatStatus.getCode() & 0xff)).array(), 1);
|
||||||
buffPos += 1;
|
|
||||||
buff.position(buffPos);
|
|
||||||
|
|
||||||
// Leg number, 1 byte
|
// Leg number, 1 byte
|
||||||
buff.put(ByteBuffer.allocate(1).put((byte) (legNumber & 0xff)).array());
|
putInBuffer(ByteBuffer.allocate(1).put((byte) (legNumber & 0xff)).array(), 1);
|
||||||
buffPos += 1;
|
|
||||||
buff.position(buffPos);
|
|
||||||
|
|
||||||
// Number of penalties awarded, 1 byte
|
// Number of penalties awarded, 1 byte
|
||||||
buff.put(ByteBuffer.allocate(1).put((byte) (numberPenaltiesAwarded & 0xff)).array());
|
putInBuffer(ByteBuffer.allocate(1).put((byte) (numberPenaltiesAwarded & 0xff)).array(), 1);
|
||||||
buffPos += 1;
|
|
||||||
buff.position(buffPos);
|
|
||||||
|
|
||||||
// Number of penalties served, 1 byte
|
// Number of penalties served, 1 byte
|
||||||
buff.put(ByteBuffer.allocate(1).put((byte) (numberPenaltiesServed & 0xff)).array());
|
putInBuffer(ByteBuffer.allocate(1).put((byte) (numberPenaltiesServed & 0xff)).array(), 1);
|
||||||
buffPos += 1;
|
|
||||||
buff.position(buffPos);
|
|
||||||
|
|
||||||
// Estimated time at next mark, 6 bytes
|
// Estimated time at next mark, 6 bytes
|
||||||
buff.put(ByteBuffer.allocate(6).putInt((int) estimatedTimeAtNextMark).array());
|
putInBuffer(Message.intToByteArray((int) estimatedTimeAtNextMark, 6),6);
|
||||||
buffPos += 6;
|
|
||||||
buff.position(buffPos);
|
|
||||||
|
|
||||||
// Estimated time at finish, 6 bytes
|
// Estimated time at finish, 6 bytes
|
||||||
buff.put(ByteBuffer.allocate(6).putInt((int) estimatedTimeAtFinish).array());
|
putInBuffer(Message.intToByteArray((int) estimatedTimeAtFinish, 6), 6);
|
||||||
buffPos += 6;
|
|
||||||
buff.position(buffPos);
|
|
||||||
|
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ public abstract class Message {
|
|||||||
* @param size number of bytes
|
* @param size number of bytes
|
||||||
*/
|
*/
|
||||||
void putBytes(ByteBuffer bytes, int size){
|
void putBytes(ByteBuffer bytes, int size){
|
||||||
buffer.put(bytes);
|
buffer.put(bytes.array());
|
||||||
moveBufferPositionBy(size);
|
moveBufferPositionBy(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ public class Boat {
|
|||||||
private double speed; // in mm/sec
|
private double speed; // in mm/sec
|
||||||
private String boatName, shortName, shorterName;
|
private String boatName, shortName, shorterName;
|
||||||
private boolean isFinished;
|
private boolean isFinished;
|
||||||
|
private long estimatedTimeTillFinish;
|
||||||
|
|
||||||
private Corner lastPassedCorner, headingCorner;
|
private Corner lastPassedCorner, headingCorner;
|
||||||
|
|
||||||
@@ -18,6 +19,7 @@ public class Boat {
|
|||||||
this.sourceID = sourceID;
|
this.sourceID = sourceID;
|
||||||
this.boatName = boatName;
|
this.boatName = boatName;
|
||||||
this.isFinished = false;
|
this.isFinished = false;
|
||||||
|
estimatedTimeTillFinish = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -116,4 +118,8 @@ public class Boat {
|
|||||||
public void setFinished(boolean finished) {
|
public void setFinished(boolean finished) {
|
||||||
isFinished = finished;
|
isFinished = finished;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getEstimatedTimeTillFinish(){
|
||||||
|
return (long) (getSpeed()) + System.currentTimeMillis();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user