- Made classes for Heartbeat message, race status message, xml messag,e racestartstatus message, boat location message, mark rounding message, course wind message, average wind message. - Made a statci calculation class for calculating bytes to int or long - Message Decoder now kinda works! #story[782]main
parent
b346e10774
commit
7d7564ce15
@ -0,0 +1,33 @@
|
||||
package seng302.Networking.Utils;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 25/04/17.
|
||||
*/
|
||||
public class AverageWind extends AC35Data{
|
||||
|
||||
private int msgNum;
|
||||
private long lngTime;
|
||||
private int rawPeriod;
|
||||
private int rawSpeed;
|
||||
private int period2;
|
||||
private int speed2;
|
||||
private int period3;
|
||||
private int speed3;
|
||||
private int period4;
|
||||
private int speed4;
|
||||
|
||||
public AverageWind(int msgNum, long lngTime, int rawPeriod, int rawSpeed, int period2, int speed2, int period3, int speed3, int period4, int speed4){
|
||||
super(MessageType.AVGWIND);
|
||||
this.msgNum = msgNum;
|
||||
this.lngTime = lngTime;
|
||||
this.rawPeriod = rawPeriod;
|
||||
this.rawSpeed = rawSpeed;
|
||||
this.period2 = period2;
|
||||
this.speed2 = speed2;
|
||||
this.period3 = period3;
|
||||
this.speed3 = speed3;
|
||||
this.period4 = period4;
|
||||
this.speed4 = speed4;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,92 @@
|
||||
package seng302.Networking.Utils;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 25/04/17.
|
||||
*/
|
||||
public class ByteConverter {
|
||||
|
||||
//default for AC35 is Little Endian therefore all overloads will be done with Little_Endian unless told else wise
|
||||
|
||||
public static int bytesToInt(byte bite){
|
||||
byte[] bytes = {bite};
|
||||
return bytesToInt(bytes, ByteOrder.LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
public static int bytesToInt(byte bite, ByteOrder byteOrder){
|
||||
byte[] bytes = {bite};
|
||||
return bytesToInt(bytes, byteOrder);
|
||||
}
|
||||
|
||||
public static int bytesToInt(byte[] bytes){
|
||||
return bytesToInt(bytes, ByteOrder.LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
public static int bytesToInt(byte[] bytes, ByteOrder byteOrder){
|
||||
byte[] bites = new byte[4];
|
||||
if (byteOrder == ByteOrder.LITTLE_ENDIAN){
|
||||
for (int i = 0; i < bytes.length; i++){
|
||||
bites[i] = bytes[i];
|
||||
if (i > 4){//break if over the limit
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = bytes.length; i < 4; i++){
|
||||
bites[i] = 0b0;
|
||||
}
|
||||
}else{//if big endian
|
||||
for (int i = 0; i < 4 - bytes.length; i++) {
|
||||
bites[i] = 0b0;
|
||||
}
|
||||
for (int i = 4 - bytes.length; i < 4; i++) {
|
||||
bites[i] = bytes[i];
|
||||
if (i > 4){//break if over the limit
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ByteBuffer.wrap(bites).order(byteOrder).getInt();
|
||||
}
|
||||
|
||||
public static long bytesToLong(byte bite){
|
||||
byte[] bytes = {bite};
|
||||
return bytesToLong(bytes, ByteOrder.LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
public static long bytesToLong(byte bite, ByteOrder byteOrder){
|
||||
byte[] bytes = {bite};
|
||||
return bytesToLong(bytes, byteOrder);
|
||||
}
|
||||
|
||||
public static long bytesToLong(byte[] bytes){
|
||||
return bytesToLong(bytes, ByteOrder.LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
public static long bytesToLong(byte[] bytes, ByteOrder byteOrder){
|
||||
byte[] bites = new byte[8];
|
||||
if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
bites[i] = bytes[i];
|
||||
if (i > 8){//break if over hte limit
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = bytes.length; i < 8; i++) {
|
||||
bites[i] = 0b0;
|
||||
}
|
||||
}else{//if big endian
|
||||
for (int i = 0; i < 8 - bytes.length; i++) {
|
||||
bites[i] = 0b0;
|
||||
}
|
||||
for (int i = 8 - bytes.length; i < 8; i++) {
|
||||
bites[i] = bytes[i];
|
||||
if (i > 8){//break if over the limit
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ByteBuffer.wrap(bites).order(byteOrder).getInt();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package seng302.Networking.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 25/04/17.
|
||||
*/
|
||||
public class CourseWinds extends AC35Data{
|
||||
|
||||
private int msgVerNum;
|
||||
private int selectedWindID;
|
||||
private ArrayList<CourseWind> courseWinds;
|
||||
|
||||
public CourseWinds(int msgVerNum, int selectedWindID, ArrayList<CourseWind> courseWinds){
|
||||
super(MessageType.COURSEWIND);
|
||||
this.msgVerNum = msgVerNum;
|
||||
this.selectedWindID = selectedWindID;
|
||||
this.courseWinds = courseWinds;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
package seng302.Networking.Utils;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 25/04/17.
|
||||
*/
|
||||
public class Heartbeat extends AC35Data{
|
||||
|
||||
public Heartbeat(){
|
||||
super(MessageType.HEARTBEAT);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
package seng302.Networking.Utils;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 25/04/17.
|
||||
*/
|
||||
public class MarkRounding extends AC35Data{
|
||||
|
||||
private int msgVerNum;
|
||||
private long time;
|
||||
private int ackNum;
|
||||
private int raceID;
|
||||
private int sourceID;
|
||||
private int boatStatus;
|
||||
private int roundingSide;
|
||||
private int markType;
|
||||
private int markID;
|
||||
|
||||
public static int BoatStatusUnknown = 0;
|
||||
public static int BoatStatusRacing = 1;
|
||||
public static int BoatStatusDSQ = 2;
|
||||
public static int BoatStatusWithdrawn = 3;
|
||||
|
||||
public static int RoundingSideUnknown = 0;
|
||||
public static int RoundingSidePort = 1;
|
||||
public static int RoundingSideStarboard = 2;
|
||||
|
||||
public static int MarkTypeUnknown = 0;
|
||||
public static int MarkTypeRoundingMark = 1;
|
||||
public static int MarkTypeGate = 2;
|
||||
|
||||
public static int MarkIDEntryLimitLine = 100;
|
||||
public static int MarkIDEntryLine = 101;
|
||||
public static int MarkIDRaceStartStartline = 102;
|
||||
public static int MarkIDRaceFinishline = 103;
|
||||
public static int MarkIDSpeedTestStart = 104;
|
||||
public static int MarkIDSpeedTestFinish = 105;
|
||||
public static int MarkIDClearStart = 106;
|
||||
|
||||
public MarkRounding(int msgVerNum, long time, int ackNum, int raceID, int sourceID, int boatStatus, int roundingSide, int markType, int markID){
|
||||
super(MessageType.MARKROUNDING);
|
||||
this.msgVerNum = msgVerNum;
|
||||
this.time = time;
|
||||
this.ackNum = ackNum;
|
||||
this.raceID = raceID;
|
||||
this.sourceID = sourceID;
|
||||
this.boatStatus = boatStatus;
|
||||
this.roundingSide = roundingSide;
|
||||
this.markType = markType;
|
||||
this.markID = markID;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package seng302.Networking.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 25/04/17.
|
||||
*/
|
||||
public class RaceStartStatus extends AC35Data{
|
||||
private long timestamp;
|
||||
private int ackNum;
|
||||
private long raceStartTime;
|
||||
private int raceID;
|
||||
private int notificationType;
|
||||
|
||||
public RaceStartStatus(long timestamp, int ackNum, long raceStartTime, int raceID, int notificationType){
|
||||
super(MessageType.RACESTARTSTATUS);
|
||||
this.timestamp = timestamp;
|
||||
this.ackNum = ackNum;
|
||||
this.raceStartTime = raceStartTime;
|
||||
this.raceID = raceID;
|
||||
this.notificationType = notificationType;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package seng302.Networking.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 25/04/17.
|
||||
*/
|
||||
public class RaceStatus extends AC35Data{
|
||||
long currentTime;
|
||||
int raceID;
|
||||
int raceStatus;
|
||||
long expectedStartTime;
|
||||
int windDirection;
|
||||
int windSpeed;
|
||||
int raceType;
|
||||
ArrayList<BoatStatus> boatStatuses;
|
||||
|
||||
public RaceStatus(long currentTime, int raceID, int raceStatus, long expectedStartTime, int windDirection, int windSpeed, int raceType, ArrayList<BoatStatus> boatStatuses){
|
||||
super(MessageType.RACESTATUS);
|
||||
this.currentTime = currentTime;
|
||||
this.raceID = raceID;
|
||||
this.raceStatus = raceStatus;
|
||||
this.expectedStartTime = expectedStartTime;
|
||||
this.windDirection = windDirection;
|
||||
this.windSpeed = windSpeed;
|
||||
this.raceType = raceType;
|
||||
this.boatStatuses = boatStatuses;//note this is a copy so any alterations to the parent will affect this.
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package seng302.Networking.Utils;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 25/04/17.
|
||||
*/
|
||||
public class XMLMessage extends AC35Data{
|
||||
|
||||
private int ackNumber;
|
||||
private long timeStamp;
|
||||
private int xmlMsgSubType;
|
||||
private int sequenceNumber;
|
||||
private int xmlMsgLength;
|
||||
private String xmlMessage;
|
||||
|
||||
public static int XMLTypeRegatta = 5;
|
||||
public static int XMLTypeRace = 6;
|
||||
public static int XMLTypeBoat = 7;
|
||||
|
||||
public XMLMessage(int ackNumber, long timeStamp, int xmlMsgSubType, int sequenceNumber, int xmlMsgLength, String xmlMessage){
|
||||
super(MessageType.XMLMESSAGE);
|
||||
this.ackNumber = ackNumber;
|
||||
this.timeStamp = timeStamp;
|
||||
this.xmlMsgSubType = xmlMsgSubType;
|
||||
this.sequenceNumber = sequenceNumber;
|
||||
this.xmlMsgLength = xmlMsgLength;
|
||||
this.xmlMessage = xmlMessage;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue