View Javadoc

1   /**
2    * Pyx4me framework
3    * Copyright (C) 2006-2008 pyx4j.com.
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing,
12   * software distributed under the License is distributed on an
13   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14   * KIND, either express or implied.  See the License for the
15   * specific language governing permissions and limitations
16   * under the License.
17   * 
18   * @author vlads
19   * @version $Id: DeviceClassConsts.java 2066 2008-06-21 23:16:18Z vlads $
20   */
21  package com.pyx4me.maven.obex;
22  
23  import javax.bluetooth.DeviceClass;
24  
25  public class DeviceClassConsts {
26  	/*
27  	 * service classes
28  	 */
29  
30  	public static final int LIMITED_DISCOVERY_SERVICE = 0x002000;
31  
32  	public static final int RESERVED1_SERVICE = 0x004000;
33  
34  	public static final int RESERVED2_SERVICE = 0x008000;
35  
36  	public static final int POSITIONING_SERVICE = 0x010000;
37  
38  	public static final int NETWORKING_SERVICE = 0x020000;
39  
40  	public static final int RENDERING_SERVICE = 0x040000;
41  
42  	public static final int CAPTURING_SERVICE = 0x080000;
43  
44  	public static final int OBJECT_TRANSFER_SERVICE = 0x100000;
45  
46  	public static final int AUDIO_SERVICE = 0x200000;
47  
48  	public static final int TELEPHONY_SERVICE = 0x400000;
49  
50  	public static final int INFORMATION_SERVICE = 0x800000;
51  
52  	/*
53  	 * major class codes
54  	 */
55  
56  	public static final int MAJOR_MISCELLANEOUS = 0x0000;
57  
58  	public static final int MAJOR_COMPUTER = 0x0100;
59  
60  	public static final int MAJOR_PHONE = 0x0200;
61  
62  	public static final int MAJOR_LAN_ACCESS = 0x0300;
63  
64  	public static final int MAJOR_AUDIO = 0x0400;
65  
66  	public static final int MAJOR_PERIPHERAL = 0x0500;
67  
68  	public static final int MAJOR_IMAGING = 0x0600;
69  
70  	public static final int MAJOR_UNCLASSIFIED = 0x1F00;
71  
72  	/*
73  	 * minor class codes
74  	 */
75  
76  	public static final int COMPUTER_MINOR_UNCLASSIFIED = 0x00;
77  
78  	public static final int COMPUTER_MINOR_DESKTOP = 0x04;
79  
80  	public static final int COMPUTER_MINOR_SERVER = 0x08;
81  
82  	public static final int COMPUTER_MINOR_LAPTOP = 0x0c;
83  
84  	public static final int COMPUTER_MINOR_HANDHELD = 0x10;
85  
86  	public static final int COMPUTER_MINOR_PALM = 0x14;
87  
88  	public static final int COMPUTER_MINOR_WEARABLE = 0x18;
89  
90  	public static final int PHONE_MINOR_UNCLASSIFIED = 0x00;
91  
92  	public static final int PHONE_MINOR_CELLULAR = 0x04;
93  
94  	public static final int PHONE_MINOR_CORDLESS = 0x08;
95  
96  	public static final int PHONE_MINOR_SMARTPHONE = 0x0c;
97  
98  	public static final int PHONE_MINOR_WIRED_MODEM = 0x10;
99  
100 	public static final int PHONE_MINOR_ISDN = 0x14;
101 
102 	public static final int PHONE_MINOR_BANANA = 0x18;
103 
104 	public static final int LAN_MINOR_TYPE_MASK = 0x1c;
105 
106 	public static final int LAN_MINOR_ACCESS_MASK = 0xe0;
107 
108 	public static final int LAN_MINOR_UNCLASSIFIED = 0x00;
109 
110 	public static final int LAN_MINOR_ACCESS_0_USED = 0x00;
111 
112 	public static final int LAN_MINOR_ACCESS_17_USED = 0x20;
113 
114 	public static final int LAN_MINOR_ACCESS_33_USED = 0x40;
115 
116 	public static final int LAN_MINOR_ACCESS_50_USED = 0x60;
117 
118 	public static final int LAN_MINOR_ACCESS_67_USED = 0x80;
119 
120 	public static final int LAN_MINOR_ACCESS_83_USED = 0xa0;
121 
122 	public static final int LAN_MINOR_ACCESS_99_USED = 0xc0;
123 
124 	public static final int LAN_MINOR_ACCESS_FULL = 0xe0;
125 
126 	public static final int AUDIO_MINOR_UNCLASSIFIED = 0x00;
127 
128 	public static final int AUDIO_MINOR_HEADSET = 0x04;
129 
130 	public static final int AUDIO_MINOR_HANDS_FREE = 0x08;
131 
132 	// public static final int AUDIO_MINOR_RESERVED = 0x0c;
133 	public static final int AUDIO_MINOR_MICROPHONE = 0x10;
134 
135 	public static final int AUDIO_MINOR_LOUDSPEAKER = 0x14;
136 
137 	public static final int AUDIO_MINOR_HEADPHONES = 0x18;
138 
139 	public static final int AUDIO_MINOR_PORTABLE_AUDIO = 0x1c;
140 
141 	public static final int AUDIO_MINOR_CAR_AUDIO = 0x20;
142 
143 	public static final int AUDIO_MINOR_SET_TOP_BOX = 0x24;
144 
145 	public static final int AUDIO_MINOR_HIFI_AUDIO = 0x28;
146 
147 	public static final int AUDIO_MINOR_VCR = 0x2c;
148 
149 	public static final int AUDIO_MINOR_VIDEO_CAMERA = 0x30;
150 
151 	public static final int AUDIO_MINOR_CAMCORDER = 0x34;
152 
153 	public static final int AUDIO_MINOR_VIDEO_MONITOR = 0x38;
154 
155 	public static final int AUDIO_MINOR_VIDEO_DISPLAY_LOUDSPEAKER = 0x3c;
156 
157 	public static final int AUDIO_MINOR_VIDEO_DISPLAY_CONFERENCING = 0x40;
158 
159 	// public static final int AUDIO_MINOR_RESERVED = 0x44;
160 	public static final int AUDIO_MINOR_GAMING_TOY = 0x48;
161 
162 	public static final int PERIPHERAL_MINOR_TYPE_MASK = 0x3c;
163 
164 	public static final int PERIPHERAL_MINOR_KEYBOARD_MASK = 0x40;
165 
166 	public static final int PERIPHERAL_MINOR_POINTER_MASK = 0x80;
167 
168 	public static final int PERIPHERAL_MINOR_UNCLASSIFIED = 0x00;
169 
170 	public static final int PERIPHERAL_MINOR_JOYSTICK = 0x04;
171 
172 	public static final int PERIPHERAL_MINOR_GAMEPAD = 0x08;
173 
174 	public static final int PERIPHERAL_MINOR_REMOTE_CONTROL = 0x0c;
175 
176 	public static final int PERIPHERAL_MINOR_SENSING = 0x10;
177 
178 	public static final int PERIPHERAL_MINOR_DIGITIZER = 0x14;
179 
180 	public static final int PERIPHERAL_MINOR_CARD_READER = 0x18;
181 
182 	public static final int IMAGING_MINOR_DISPLAY_MASK = 0x10;
183 
184 	public static final int IMAGING_MINOR_CAMERA_MASK = 0x20;
185 
186 	public static final int IMAGING_MINOR_SCANNER_MASK = 0x40;
187 
188 	public static final int IMAGING_MINOR_PRINTER_MASK = 0x80;
189 
190 	private static boolean append(StringBuffer buf, String str, boolean comma) {
191 		if (comma) {
192 			buf.append(',');
193 		}
194 
195 		buf.append(str);
196 
197 		return true;
198 	}
199 
200 	public static String toString(DeviceClass dc) {
201 		if (dc == null) {
202 			return "";
203 		}
204 		StringBuffer buf = new StringBuffer();
205 
206 		switch (dc.getMajorDeviceClass()) {
207 		case MAJOR_MISCELLANEOUS:
208 			buf.append("Miscellaneous");
209 			break;
210 		case MAJOR_COMPUTER:
211 			buf.append("Computer");
212 
213 			switch (dc.getMinorDeviceClass()) {
214 			case COMPUTER_MINOR_UNCLASSIFIED:
215 				buf.append("/Unclassified");
216 				break;
217 			case COMPUTER_MINOR_DESKTOP:
218 				buf.append("/Desktop");
219 				break;
220 			case COMPUTER_MINOR_SERVER:
221 				buf.append("/Server");
222 				break;
223 			case COMPUTER_MINOR_LAPTOP:
224 				buf.append("/Laptop");
225 				break;
226 			case COMPUTER_MINOR_HANDHELD:
227 				buf.append("/Handheld");
228 				break;
229 			case COMPUTER_MINOR_PALM:
230 				buf.append("/Palm");
231 				break;
232 			case COMPUTER_MINOR_WEARABLE:
233 				buf.append("/Wearable");
234 				break;
235 			default:
236 				buf.append("/Unknown");
237 				break;
238 			}
239 
240 			break;
241 		case MAJOR_PHONE:
242 			buf.append("Phone");
243 
244 			switch (dc.getMinorDeviceClass()) {
245 			case PHONE_MINOR_UNCLASSIFIED:
246 				buf.append("/Unclassified");
247 				break;
248 			case PHONE_MINOR_CELLULAR:
249 				buf.append("/Cellular");
250 				break;
251 			case PHONE_MINOR_CORDLESS:
252 				buf.append("/Cordless");
253 				break;
254 			case PHONE_MINOR_SMARTPHONE:
255 				buf.append("/Smartphone");
256 				break;
257 			case PHONE_MINOR_WIRED_MODEM:
258 				buf.append("/Wired Modem");
259 				break;
260 			case PHONE_MINOR_ISDN:
261 				buf.append("/ISDN");
262 				break;
263 			case PHONE_MINOR_BANANA:
264 				buf.append("/Ring ring ring ring ring ring ring");
265 				break;
266 			default:
267 				buf.append("/Unknown");
268 				break;
269 			}
270 
271 			break;
272 		case MAJOR_LAN_ACCESS: {
273 			buf.append("LAN Access");
274 
275 			int minor = dc.getMinorDeviceClass();
276 
277 			switch (minor & LAN_MINOR_TYPE_MASK) {
278 			case LAN_MINOR_UNCLASSIFIED:
279 				buf.append("/Unclassified");
280 				break;
281 			default:
282 				buf.append("/Unknown");
283 				break;
284 			}
285 
286 			switch (minor & LAN_MINOR_ACCESS_MASK) {
287 			case LAN_MINOR_ACCESS_0_USED:
288 				buf.append("/0% used");
289 				break;
290 			case LAN_MINOR_ACCESS_17_USED:
291 				buf.append("/1-17% used");
292 				break;
293 			case LAN_MINOR_ACCESS_33_USED:
294 				buf.append("/18-33% used");
295 				break;
296 			case LAN_MINOR_ACCESS_50_USED:
297 				buf.append("/34-50% used");
298 				break;
299 			case LAN_MINOR_ACCESS_67_USED:
300 				buf.append("/51-67% used");
301 				break;
302 			case LAN_MINOR_ACCESS_83_USED:
303 				buf.append("/68-83% used");
304 				break;
305 			case LAN_MINOR_ACCESS_99_USED:
306 				buf.append("/84-99% used");
307 				break;
308 			case LAN_MINOR_ACCESS_FULL:
309 				buf.append("/100% used");
310 				break;
311 			}
312 
313 			break;
314 		}
315 		case MAJOR_AUDIO:
316 			buf.append("Audio");
317 
318 			switch (dc.getMinorDeviceClass()) {
319 			case AUDIO_MINOR_UNCLASSIFIED:
320 				buf.append("/Unclassified");
321 				break;
322 			case AUDIO_MINOR_HEADSET:
323 				buf.append("/Headset");
324 				break;
325 			case AUDIO_MINOR_HANDS_FREE:
326 				buf.append("/Hands-free");
327 				break;
328 			case AUDIO_MINOR_MICROPHONE:
329 				buf.append("/Microphone");
330 				break;
331 			case AUDIO_MINOR_LOUDSPEAKER:
332 				buf.append("/Loudspeaker");
333 				break;
334 			case AUDIO_MINOR_HEADPHONES:
335 				buf.append("/Headphones");
336 				break;
337 			case AUDIO_MINOR_PORTABLE_AUDIO:
338 				buf.append("/Portable");
339 				break;
340 			case AUDIO_MINOR_CAR_AUDIO:
341 				buf.append("/Car");
342 				break;
343 			case AUDIO_MINOR_SET_TOP_BOX:
344 				buf.append("/Set-top Box");
345 				break;
346 			case AUDIO_MINOR_HIFI_AUDIO:
347 				buf.append("/HiFi");
348 				break;
349 			case AUDIO_MINOR_VCR:
350 				buf.append("/VCR");
351 				break;
352 			case AUDIO_MINOR_VIDEO_CAMERA:
353 				buf.append("/Video Camera");
354 				break;
355 			case AUDIO_MINOR_CAMCORDER:
356 				buf.append("/Camcorder");
357 				break;
358 			case AUDIO_MINOR_VIDEO_MONITOR:
359 				buf.append("/Video Monitor");
360 				break;
361 			case AUDIO_MINOR_VIDEO_DISPLAY_LOUDSPEAKER:
362 				buf.append("/Video Display Loudspeaker");
363 				break;
364 			case AUDIO_MINOR_VIDEO_DISPLAY_CONFERENCING:
365 				buf.append("/Video Display Conferencing");
366 				break;
367 			case AUDIO_MINOR_GAMING_TOY:
368 				buf.append("/Gaming Toy");
369 				break;
370 			default:
371 				buf.append("/Unknown");
372 				break;
373 			}
374 
375 			break;
376 		case MAJOR_PERIPHERAL: {
377 			buf.append("Peripheral");
378 
379 			int minor = dc.getMinorDeviceClass();
380 
381 			switch (minor & (PERIPHERAL_MINOR_KEYBOARD_MASK | PERIPHERAL_MINOR_POINTER_MASK)) {
382 			case 0:
383 				buf.append("/()");
384 				break;
385 			case PERIPHERAL_MINOR_KEYBOARD_MASK:
386 				buf.append("/(Keyboard)");
387 				break;
388 			case PERIPHERAL_MINOR_POINTER_MASK:
389 				buf.append("/(Pointer)");
390 				break;
391 			case PERIPHERAL_MINOR_KEYBOARD_MASK | PERIPHERAL_MINOR_POINTER_MASK:
392 				buf.append("/(Keyboard,Pointer)");
393 				break;
394 			}
395 
396 			switch (minor & PERIPHERAL_MINOR_TYPE_MASK) {
397 			case PERIPHERAL_MINOR_UNCLASSIFIED:
398 				buf.append("/Unclassified");
399 				break;
400 			case PERIPHERAL_MINOR_JOYSTICK:
401 				buf.append("/Joystick");
402 				break;
403 			case PERIPHERAL_MINOR_GAMEPAD:
404 				buf.append("/Gamepad");
405 				break;
406 			case PERIPHERAL_MINOR_REMOTE_CONTROL:
407 				buf.append("/Remote Control");
408 				break;
409 			case PERIPHERAL_MINOR_SENSING:
410 				buf.append("/Sensing");
411 				break;
412 			case PERIPHERAL_MINOR_DIGITIZER:
413 				buf.append("/Digitizer");
414 				break;
415 			case PERIPHERAL_MINOR_CARD_READER:
416 				buf.append("/Card Reader");
417 				break;
418 			default:
419 				buf.append("/Unknown");
420 				break;
421 			}
422 
423 			break;
424 		}
425 		case MAJOR_IMAGING: {
426 			buf.append("Peripheral/(");
427 
428 			int minor = dc.getMinorDeviceClass();
429 
430 			boolean comma = false;
431 
432 			if ((minor & IMAGING_MINOR_DISPLAY_MASK) != 0)
433 				comma = append(buf, "Display", comma);
434 			if ((minor & IMAGING_MINOR_CAMERA_MASK) != 0)
435 				comma = append(buf, "Camera", comma);
436 			if ((minor & IMAGING_MINOR_SCANNER_MASK) != 0)
437 				comma = append(buf, "Scanner", comma);
438 			if ((minor & IMAGING_MINOR_PRINTER_MASK) != 0)
439 				comma = append(buf, "Printer", comma);
440 
441 			buf.append(')');
442 
443 			break;
444 		}
445 		case MAJOR_UNCLASSIFIED:
446 			buf.append("Unclassified");
447 			break;
448 		default:
449 			buf.append("Unknown");
450 			break;
451 		}
452 
453 		buf.append("/(");
454 
455 		boolean comma = false;
456 
457 		int record = dc.getServiceClasses();
458 
459 		if ((record & LIMITED_DISCOVERY_SERVICE) != 0)
460 			comma = append(buf, "Limited Discovery", comma);
461 		if ((record & POSITIONING_SERVICE) != 0)
462 			comma = append(buf, "Positioning", comma);
463 		if ((record & NETWORKING_SERVICE) != 0)
464 			comma = append(buf, "Networking", comma);
465 		if ((record & RENDERING_SERVICE) != 0)
466 			comma = append(buf, "Rendering", comma);
467 		if ((record & CAPTURING_SERVICE) != 0)
468 			comma = append(buf, "Capturing", comma);
469 		if ((record & OBJECT_TRANSFER_SERVICE) != 0)
470 			comma = append(buf, "Object Transfer", comma);
471 		if ((record & AUDIO_SERVICE) != 0)
472 			comma = append(buf, "Audio", comma);
473 		if ((record & TELEPHONY_SERVICE) != 0)
474 			comma = append(buf, "Telephony", comma);
475 		if ((record & INFORMATION_SERVICE) != 0)
476 			comma = append(buf, "Information", comma);
477 
478 		buf.append(')');
479 
480 		return buf.toString();
481 	}
482 }