Set up Boat Action Message encoding
- Fixed command number for sails out #story[1089]
This commit is contained in:
@@ -94,6 +94,15 @@ public class BinaryMessageEncoder {
|
||||
this.fullMessage = tempFullMessageByteBuffer.array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a binary message from message type and message body.
|
||||
* @param headerMessageType of message
|
||||
* @param messageBody of message
|
||||
*/
|
||||
public BinaryMessageEncoder(MessageType headerMessageType, byte[] messageBody) {
|
||||
this(headerMessageType, System.currentTimeMillis(), 69, (short)messageBody.length, messageBody);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full encoded message. This includes the header, body, and CRC.
|
||||
* @return Full encoded message.
|
||||
|
||||
@@ -19,6 +19,7 @@ public enum MessageType {
|
||||
MARKROUNDING(38),
|
||||
COURSEWIND(44),
|
||||
AVGWIND(47),
|
||||
BOATACTION(100),
|
||||
NOTAMESSAGE(0);
|
||||
|
||||
///Primitive value of the enum.
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package visualiser.gameController;
|
||||
|
||||
import network.BinaryMessageEncoder;
|
||||
import network.Messages.Enums.MessageType;
|
||||
import visualiser.gameController.Keys.ControlKey;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
@@ -27,6 +30,7 @@ public class ControllerClient {
|
||||
*/
|
||||
public ControllerClient(Socket socket) {
|
||||
this.socket = socket;
|
||||
|
||||
try {
|
||||
this.outputStream = new DataOutputStream(socket.getOutputStream());
|
||||
} catch (IOException e) {
|
||||
@@ -40,7 +44,14 @@ public class ControllerClient {
|
||||
* @throws IOException if socket write fails
|
||||
*/
|
||||
public void sendKey(ControlKey key) throws IOException {
|
||||
// TODO - get and send action number currently corresponding to key (context dependent)
|
||||
System.out.println(key.toString() + ": " + key.getProtocolCode());
|
||||
int protocolCode = key.getProtocolCode();
|
||||
if(protocolCode > -1) {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(4);
|
||||
buffer.putInt(protocolCode);
|
||||
byte[] message = new byte[]{buffer.get(3)};
|
||||
BinaryMessageEncoder binaryMessage = new BinaryMessageEncoder(MessageType.BOATACTION, message);
|
||||
//outputStream.write(binaryMessage.getFullMessage());
|
||||
System.out.println("Binary message constructed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class ControllerServer implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
while(true) {
|
||||
byte[] key = new byte[1];
|
||||
byte[] key = new byte[16];
|
||||
try {
|
||||
inputStream.read(key);
|
||||
// TODO - handle messages received
|
||||
|
||||
@@ -19,7 +19,7 @@ public class SailsToggleKey extends ControlKey {
|
||||
*/
|
||||
@Override
|
||||
public void onAction() {
|
||||
protocolCode = protocolCode == 2? 1 : 2;
|
||||
protocolCode = protocolCode == 2? 3 : 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user