summaryrefslogtreecommitdiff
path: root/trunk/users/adrian/host/src/org/reprap/comms/messages/VersionResponseMessage.java
blob: e5ab143b7165e7a485c9ed3b08124fc9e5292be4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package org.reprap.comms.messages;

import java.io.IOException;

import org.reprap.comms.IncomingContext;
import org.reprap.comms.IncomingMessage;

/**
 *
 */
public class VersionResponseMessage extends IncomingMessage {

	/**
	 * @param incomingContext
	 * @throws IOException
	 */
	public VersionResponseMessage(IncomingContext incomingContext) throws IOException {
		super(incomingContext);
	}
	
	/**
	 * @return version number
	 * @throws InvalidPayloadException
	 */
	public int getVersion() throws InvalidPayloadException {
	    byte [] reply = getPayload();
	    if (reply == null || reply.length != 3)
	    	throw new InvalidPayloadException();
//	    System.out.println("ver: " + reply[0] + ", "
//	    		+ reply[1] + ", "
//	    		+ reply[2]);
	    return reply[2] + (reply[1] << 8);
	}

	/* (non-Javadoc)
	 * @see org.reprap.comms.IncomingMessage#isExpectedPacketType(byte)
	 */
	protected boolean isExpectedPacketType(byte packetType) {
		return packetType == VersionRequestMessage.MSG_GetVersion;
	}

}