summaryrefslogtreecommitdiff
path: root/tags/host/0.8.1/src/org/reprap/comms/messages/VersionResponseMessage.java
blob: 44961c73fe1c65ab9e980b0bf1a1b05645bbd1d8 (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
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();
	    return reply[1] + reply[2] << 8;
	}

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

}