|
|
|
|
@ -1,7 +1,10 @@
|
|
|
|
|
package seng302.Model;
|
|
|
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created by fwy13 on 19/04/17.
|
|
|
|
|
@ -117,6 +120,46 @@ public class RaceVisionByteEncoder {
|
|
|
|
|
return result.array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte[] yachtEventCode(long time, short acknowledgeNumber, int raceID, int destSourceID, int incidentID,
|
|
|
|
|
int eventID){
|
|
|
|
|
int messageVersion = 0b10;
|
|
|
|
|
byte[] encodeTime = convert(time, 6);
|
|
|
|
|
short ackNum = acknowledgeNumber;
|
|
|
|
|
int raceUID = raceID;//TODO chekc if this is an into for a 4 char string.
|
|
|
|
|
int destSource = destSourceID;
|
|
|
|
|
int incident = incidentID;
|
|
|
|
|
byte[] event = convert(eventID, 1);
|
|
|
|
|
|
|
|
|
|
ByteBuffer result = ByteBuffer.allocate(22);
|
|
|
|
|
result.put(convert(messageVersion, 1));
|
|
|
|
|
result.put(encodeTime);
|
|
|
|
|
result.putShort(ackNum);
|
|
|
|
|
result.putInt(raceUID);
|
|
|
|
|
result.putInt(destSource);
|
|
|
|
|
result.putInt(incident);
|
|
|
|
|
result.put(event);
|
|
|
|
|
return result.array();
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
public byte[] chatterText(int messageType, String message){
|
|
|
|
|
int messageVersion = 0b1;
|
|
|
|
|
byte[] type = convert(messageType, 1);
|
|
|
|
|
byte[] length = convert(message.length(), 1);
|
|
|
|
|
byte[] messageBytes = message.getBytes(Charset.forName("UTF-8"));
|
|
|
|
|
|
|
|
|
|
//byte[] text =
|
|
|
|
|
return;
|
|
|
|
|
}*/
|
|
|
|
|
/*
|
|
|
|
|
public byte[] convert(String s, int size){
|
|
|
|
|
byte[] m = s.getBytes(Charset.forName("UTF-8"));
|
|
|
|
|
int length = m.length;
|
|
|
|
|
if (length > 255){
|
|
|
|
|
length = 255;
|
|
|
|
|
}
|
|
|
|
|
byte[] result = Arrays.copyOfRange(m, 0, length + 1);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
public byte[] convert(int n, int size){
|
|
|
|
|
byte[] result;
|
|
|
|
|
if (size > 4){
|