- Binary Message Decoder now can determine whether the files are correct or not - Boat Location Message is now a extension of AC35Data which will be read by the TCPClient - Boat Status is now an extension of AC35Data which will be read by the TCPClient - CourseWind is now an extension of AC35Data which will be read by TCPClient - ValueOf static method added MessageType to assist in determining the packet that was received. - Race Message is now an extension of AC35Data which will be read by TCPClient - PacketDumpReader created to read the sample file that was provided. - AC35Packet has been made to store each Dumped file packet. - AC35 Data Dump has been added to resources/dataDumps as ac35.bin #story[782]main
parent
d960bc67a2
commit
c0bf5b1641
@ -0,0 +1,67 @@
|
|||||||
|
package seng302.Networking.PacketDump;
|
||||||
|
|
||||||
|
import seng302.Networking.BinaryMesageEncoder;
|
||||||
|
import seng302.Networking.BinaryMessageDecoder;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by fwy13 on 25/04/17.
|
||||||
|
*/
|
||||||
|
public class AC35DumpReader {
|
||||||
|
|
||||||
|
private byte[] dump;
|
||||||
|
private ArrayList<AC35Packet> packets;
|
||||||
|
|
||||||
|
public AC35DumpReader(String url) throws IOException, URISyntaxException {
|
||||||
|
|
||||||
|
URL uri = getClass().getClassLoader().getResource(url);
|
||||||
|
Path path = Paths.get(uri.toURI());
|
||||||
|
dump = Files.readAllBytes(path);
|
||||||
|
|
||||||
|
packets = new ArrayList<>();
|
||||||
|
|
||||||
|
System.out.println(dump.length);
|
||||||
|
readAllPackets();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void readAllPackets(){
|
||||||
|
int pointer = 0;
|
||||||
|
while(pointer < dump.length){
|
||||||
|
byte[] messLen = new byte[2];
|
||||||
|
messLen[1] = dump[pointer + 13];
|
||||||
|
messLen[0] = dump[pointer + 14];
|
||||||
|
int messageLength = ByteBuffer.wrap(messLen).getShort();
|
||||||
|
//System.out.println(messageLength);
|
||||||
|
|
||||||
|
packets.add(new AC35Packet(Arrays.copyOfRange(dump, pointer, pointer + messageLength + 19)));
|
||||||
|
|
||||||
|
pointer += 19 + messageLength;
|
||||||
|
}
|
||||||
|
for (AC35Packet pack: packets){
|
||||||
|
BinaryMessageDecoder decoder = new BinaryMessageDecoder(pack.getData());
|
||||||
|
decoder.decode();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args){
|
||||||
|
try {
|
||||||
|
AC35DumpReader ac35DumpReader = new AC35DumpReader("dataDumps/ac35.bin");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package seng302.Networking.PacketDump;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by fwy13 on 25/04/17.
|
||||||
|
*/
|
||||||
|
public class AC35Packet {
|
||||||
|
|
||||||
|
byte[] data;
|
||||||
|
|
||||||
|
public AC35Packet(byte[] data){
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package seng302.Networking.Utils;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by fwy13 on 25/04/17.
|
||||||
|
*/
|
||||||
|
public abstract class AC35Data {
|
||||||
|
|
||||||
|
protected MessageType type;
|
||||||
|
|
||||||
|
public AC35Data (MessageType type){
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Binary file not shown.
Loading…
Reference in new issue