mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Fixed a bug where boat statuses were being sent incorrectly
- Boats now have an estimated time until finish - Boat packets are being sent correctly Tags: #story[829]
This commit is contained in:
@@ -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,48 +108,53 @@ 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) {
|
||||||
switch (packet.getType()){
|
try{
|
||||||
case HEARTBEAT:
|
switch (packet.getType()){
|
||||||
extractHeartBeat(packet);
|
case HEARTBEAT:
|
||||||
break;
|
extractHeartBeat(packet);
|
||||||
case RACE_STATUS:
|
break;
|
||||||
extractRaceStatus(packet);
|
case RACE_STATUS:
|
||||||
break;
|
extractRaceStatus(packet);
|
||||||
case DISPLAY_TEXT_MESSAGE:
|
break;
|
||||||
extractDisplayMessage(packet);
|
case DISPLAY_TEXT_MESSAGE:
|
||||||
break;
|
extractDisplayMessage(packet);
|
||||||
case XML_MESSAGE:
|
break;
|
||||||
extractXmlMessage(packet);
|
case XML_MESSAGE:
|
||||||
break;
|
extractXmlMessage(packet);
|
||||||
case RACE_START_STATUS:
|
break;
|
||||||
extractRaceStartStatus(packet);
|
case RACE_START_STATUS:
|
||||||
break;
|
extractRaceStartStatus(packet);
|
||||||
case YACHT_EVENT_CODE:
|
break;
|
||||||
extractYachtEventCode(packet);
|
case YACHT_EVENT_CODE:
|
||||||
break;
|
extractYachtEventCode(packet);
|
||||||
case YACHT_ACTION_CODE:
|
break;
|
||||||
extractYachtActionCode(packet);
|
case YACHT_ACTION_CODE:
|
||||||
break;
|
extractYachtActionCode(packet);
|
||||||
case CHATTER_TEXT:
|
break;
|
||||||
extractChatterText(packet);
|
case CHATTER_TEXT:
|
||||||
break;
|
extractChatterText(packet);
|
||||||
case BOAT_LOCATION:
|
break;
|
||||||
extractBoatLocation(packet);
|
case BOAT_LOCATION:
|
||||||
break;
|
extractBoatLocation(packet);
|
||||||
case MARK_ROUNDING:
|
break;
|
||||||
extractMarkRounding(packet);
|
case MARK_ROUNDING:
|
||||||
break;
|
extractMarkRounding(packet);
|
||||||
case COURSE_WIND:
|
break;
|
||||||
extractCourseWind(packet);
|
case COURSE_WIND:
|
||||||
break;
|
extractCourseWind(packet);
|
||||||
case AVG_WIND:
|
break;
|
||||||
extractAvgWind(packet);
|
case AVG_WIND:
|
||||||
break;
|
extractAvgWind(packet);
|
||||||
default:
|
break;
|
||||||
break;
|
default:
|
||||||
//System.out.println(packet.getType().toString());
|
break;
|
||||||
}
|
//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