View Javadoc

1   /*
2    * Copyright 2007-2008 Volker Fritzsch
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License. 
15   */
16  package motej.request;
17  
18  /**
19   * Requests a specific DataReport mode.
20   * <p>
21   * @author <a href="mailto:vfritzsch@users.sourceforge.net">Volker Fritzsch</a>
22   */
23  public class ReportModeRequest implements MoteRequest {
24  
25  	/**
26  	 * Status Information
27  	 * <p>
28  	 * <i>not requestable</i>
29  	 */
30  	public static final byte DATA_REPORT_0x20 = 0x20;
31  	
32  	/**
33  	 * Answer report to read data command (0x17)
34  	 * <p>
35  	 * <i>not requestable</i>
36  	 */
37  	public static final byte DATA_REPORT_0x21 = 0x21;
38  	
39  	/**
40  	 * Core Buttons
41  	 */
42  	public static final byte DATA_REPORT_0x30 = 0x30;
43  	
44  	/**
45  	 * Core Buttons and Accelerometer
46  	 */
47  	public static final byte DATA_REPORT_0x31 = 0x31;
48  	
49  	/**
50  	 * Core Buttons with 8 Extension bytes
51  	 */
52  	public static final byte DATA_REPORT_0x32 = 0x32;
53  	
54  	/**
55  	 * Core Buttons and Accelerometer with 12 IR bytes
56  	 */
57  	public static final byte DATA_REPORT_0x33 = 0x33;
58  	
59  	/**
60  	 * Core Buttons with 19 Extension bytes
61  	 */
62  	public static final byte DATA_REPORT_0x34 = 0x34;
63  	
64  	/**
65  	 * Core Buttons and Accelerometer with 16 Extension Bytes
66  	 */
67  	public static final byte DATA_REPORT_0x35 = 0x35;
68  	
69  	/**
70  	 * Core Buttons with 10 IR bytes and 9 Extension Bytes
71  	 */
72  	public static final byte DATA_REPORT_0x36 = 0x36;
73  
74  	/**
75  	 * Core Buttons and Accelerometer with 10 IR bytes and 6 Extension Bytes
76  	 */
77  	public static final byte DATA_REPORT_0x37 = 0x37;
78  	
79  	/**
80  	 * 21 Extension Bytes
81  	 */
82  	public static final byte DATA_REPORT_0x3d = 0x3d;
83  	
84  	/**
85  	 * Interleaved Core Buttons and Accelerometer with 36 IR bytes
86  	 * 
87  	 * @see motej.request#DATA_REPORT_0x3f
88  	 */
89  	public static final byte DATA_REPORT_0x3e = 0x3e;
90  	
91  	/**
92  	 * Interleaved Core Buttons and Accelerometer with 36 IR bytes
93  	 * 
94  	 * @see motej.request#DATA_REPORT_0x3e
95  	 */
96  	public static final byte DATA_REPORT_0x3f = 0x3f;
97  	
98  	private byte mode;
99  	
100 	private boolean continuous;
101 	
102 	public ReportModeRequest(byte mode) {
103 		this(mode, false);
104 	}
105 	
106 	public ReportModeRequest(byte mode, boolean continuous) {
107 		if (mode < 0x30 || (mode > 0x37 && mode < 0x3d) || mode > 0x3f) {
108 			throw new IllegalArgumentException("Undefined data report mode");
109 		}
110 		this.mode = mode;
111 		this.continuous = continuous;
112 	}
113 	
114 	public byte[] getBytes() {
115 		return new byte[] { 82, 18, continuous ? (byte) 4 : (byte) 0, mode };
116 	}
117 
118 }