My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* BlueCove - Java library for Bluetooth
* Copyright (C) 2006-2007 Vlad Skarzhevskyy
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* @author vlads
* @version $Id$
*/
package net.sf.bluecove;

import javax.bluetooth.BluetoothStateException;
import javax.bluetooth.L2CAPConnection;
import javax.bluetooth.LocalDevice;

import org.bluecove.tester.log.Logger;
import org.bluecove.tester.util.RuntimeDetect;
import org.bluecove.tester.util.StringUtils;

import junit.framework.Assert;
import net.sf.bluecove.util.BluetoothTypesInfo;

/**
*
*/
public class TestResponderCommon {

public static int receiveMTU_max = L2CAPConnection.DEFAULT_MTU;

public static void printProperty(String property) {
String val = LocalDevice.getProperty(property);
if (val != null) {
Logger.info(property + ":" + val);
}
}

public static void initLocalDevice() {
if (!Configuration.isConfigured) {
try {
initLocalDeviceConfig();
} catch (BluetoothStateException e) {
Logger.error("can't init LocalDevice", e);
}
}
}

public static void startLocalDevice() throws BluetoothStateException {
if (!Configuration.initializeLocalDevice) {
return;
}
initLocalDeviceConfig();
}

private static void initLocalDeviceConfig() throws BluetoothStateException {
RuntimeDetect.cldcStub.setThreadLocalBluetoothStack(Configuration.threadLocalBluetoothStack);
LocalDevice localDevice = LocalDevice.getLocalDevice();
printLocalDeviceInfo();
String bluecoveVersion = LocalDevice.getProperty("bluecove");
if (StringUtils.isStringSet(bluecoveVersion)) {
RuntimeDetect.isBlueCove = true;
Assert.assertNotNull("BT Address is null", localDevice.getBluetoothAddress());
if (!Configuration.windowsCE) {
Assert.assertNotNull("BT Name is null", localDevice.getFriendlyName());
}
Configuration.stackWIDCOMM = StringUtils.equalsIgnoreCase("WIDCOMM", LocalDevice.getProperty("bluecove.stack"));
String featureL2cap = LocalDevice.getProperty("bluecove.feature.l2cap");
if (featureL2cap == null) {
Configuration.supportL2CAP = Configuration.stackWIDCOMM || Configuration.macOSx || Configuration.linux;
} else {
Configuration.supportL2CAP = "true".equals(featureL2cap);
}
}
String receiveMTUstr = LocalDevice.getProperty("bluetooth.l2cap.receiveMTU.max");
if ((receiveMTUstr != null) && (receiveMTUstr.length() > 0)) {
try {
int max = Integer.valueOf(receiveMTUstr).intValue();
if (max < receiveMTU_max) {
receiveMTU_max = max;
}
} catch (NumberFormatException ignore) {
}
}
Configuration.isConfigured = true;
}

public static void printLocalDeviceInfo() throws BluetoothStateException {
RuntimeDetect.cldcStub.setThreadLocalBluetoothStack(Configuration.threadLocalBluetoothStack);
LocalDevice localDevice = LocalDevice.getLocalDevice();
Logger.info("address:" + localDevice.getBluetoothAddress());
Logger.info("name:" + localDevice.getFriendlyName());
Logger.info("class:" + BluetoothTypesInfo.toString(localDevice.getDeviceClass()));

printProperty("bluetooth.api.version");
printProperty("bluetooth.sd.trans.max");
printProperty("bluetooth.sd.attr.retrievable.max");
printProperty("bluetooth.connected.devices.max");
printProperty("bluetooth.connected.inquiry.scan");
printProperty("bluetooth.connected.page.scan");
printProperty("bluetooth.connected.inquiry");
printProperty("bluetooth.l2cap.receiveMTU.max");

String bluecoveVersion = LocalDevice.getProperty("bluecove");
if (StringUtils.isStringSet(bluecoveVersion)) {
Logger.info("bluecove version:" + bluecoveVersion);
Logger.info("stack:" + LocalDevice.getProperty("bluecove.stack"));
Logger.info("stack version:" + LocalDevice.getProperty("bluecove.stack.version"));
Logger.info("radio manufacturer:" + LocalDevice.getProperty("bluecove.radio.manufacturer"));
Logger.info("radio version:" + LocalDevice.getProperty("bluecove.radio.version"));

Logger.info("feature L2CAP:" + LocalDevice.getProperty("bluecove.feature.l2cap"));
Logger.info("feature setDeviceServiceClasses:" + LocalDevice.getProperty("bluecove.feature.set_device_service_classes"));
Logger.info("feature RSSI:" + LocalDevice.getProperty("bluecove.feature.rssi"));

printProperty("bluecove.connections");
String id = LocalDevice.getProperty("bluecove.deviceID");
if (id != null) {
Logger.info("bluecove.deviceID:" + id);
}
String ids = LocalDevice.getProperty("bluecove.local_devices_ids");
if (ids != null) {
Logger.info("local devices ID:" + ids);
}
}
}

public static String niceDeviceName(String bluetoothAddress) {
String w = getWhiteDeviceName(bluetoothAddress);
if (w == null) {
w = (String) TestResponderClient.recentDeviceNames.get(bluetoothAddress.toUpperCase());
}
return (w != null) ? w : bluetoothAddress;
}

public static String getWhiteDeviceName(String bluetoothAddress) {
if ((bluetoothAddress == null) || (Configuration.testDeviceNames == null)) {
return null;
}
String addr = bluetoothAddress.toUpperCase();
return (String) Configuration.testDeviceNames.get(addr);
}

}

Change log

r2736 by skarzhevskyy on Feb 12, 2009   Diff
Adding property bluecove.feature.rssi
Go to: 
Project members, sign in to write a code review

Older revisions

r2730 by skarzhevskyy on Feb 11, 2009   Diff
work with local device properties
r2607 by skarzhevskyy on Dec 17, 2008   Diff
OBEX tests in J2ME
r2471 by skarzhevskyy on Nov 30, 2008   Diff
Change license to Apache License,
Version 2.0, Update headers
All revisions of this file

File info

Size: 6150 bytes, 157 lines

File properties

svn:mime-type
text/plain
svn:eol-style
native
svn:keywords
Date Author Id Revision
Powered by Google Project Hosting