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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/**
* 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 java.util.Hashtable;

import javax.bluetooth.RemoteDevice;
import javax.bluetooth.ServiceRecord;

import net.sf.bluecove.util.TimeStatistic;

/**
*
*/
public class RemoteDeviceInfo {

public static Hashtable devices = new Hashtable();

public static Hashtable services = new Hashtable();

public String name;

public RemoteDevice remoteDevice;

public int discoveredCount;

public long discoveredFirstTime;

public long discoveredLastTime;

private TimeStatistic deviceDiscovery = new TimeStatistic();

public static TimeStatistic deviceInquiryDuration = new TimeStatistic();

public TimeStatistic serviceSearch = new TimeStatistic();

public static TimeStatistic allServiceSearch = new TimeStatistic();

public long serviceDiscoveredFirstTime;

public long serviceDiscoveredLastTime;

public TimeStatistic serviceDiscovered = new TimeStatistic();

public long variableData;

public long variableDataCheckLastTime;

public boolean variableDataUpdated = false;

public static synchronized void clear() {
devices = new Hashtable();
services = new Hashtable();
allServiceSearch.clear();
deviceInquiryDuration.clear();
}

public static synchronized RemoteDeviceInfo getDevice(RemoteDevice remoteDevice) {
String addr = remoteDevice.getBluetoothAddress().toUpperCase();
RemoteDeviceInfo devInfo = getDevice(addr);
devInfo.remoteDevice = remoteDevice;
return devInfo;
}

public static synchronized RemoteDeviceInfo getDevice(String remoteDeviceAddress) {
RemoteDeviceInfo devInfo = (RemoteDeviceInfo) devices.get(remoteDeviceAddress);
if (devInfo == null) {
devInfo = new RemoteDeviceInfo();
devInfo.name = TestResponderClient.niceDeviceName(remoteDeviceAddress);
devices.put(remoteDeviceAddress, devInfo);
}
return devInfo;
}

public static synchronized void deviceFound(RemoteDevice remoteDevice) {
RemoteDeviceInfo devInfo = getDevice(remoteDevice);
long now = System.currentTimeMillis();
if (devInfo.discoveredCount == 0) {
devInfo.discoveredFirstTime = now;
devInfo.deviceDiscovery.add(0);
} else {
devInfo.deviceDiscovery.add(now - devInfo.discoveredLastTime);
}
devInfo.remoteDevice = remoteDevice;
devInfo.discoveredCount++;
devInfo.discoveredLastTime = now;
}

public static synchronized void deviceServiceFound(RemoteDevice remoteDevice, long variableData) {
RemoteDeviceInfo devInfo = getDevice(remoteDevice);
long now = System.currentTimeMillis();
if (devInfo.serviceDiscovered.count == 0) {
devInfo.serviceDiscoveredFirstTime = now;
devInfo.serviceDiscovered.add(0);
} else {
devInfo.serviceDiscovered.add(now - devInfo.serviceDiscoveredLastTime);
}
devInfo.remoteDevice = remoteDevice;
devInfo.serviceDiscoveredLastTime = now;
// if (variableData != 0) {
// long frequencyMSec = now - devInfo.variableDataCheckLastTime;
// if ((devInfo.variableData != 0) && (frequencyMSec > 1000 * 120)) {
// devInfo.variableDataCheckLastTime = now;
// boolean er = false;
// if (variableData == devInfo.variableData) {
// Logger.warn("not updated " + variableData);
// TestResponderClient.failure.addFailure("not updated " + variableData
// + " on " + devInfo.name);
// er = true;
// }
// if (!er) {
// devInfo.variableDataUpdated = true;
// Logger.info("Var info updated, " + variableData);
// }
// } else if (devInfo.variableData != variableData) {
// if (devInfo.variableData == 0) {
// Logger.info("Var info set, " + variableData);
// } else {
// Logger.info("Var info updated, " + variableData);
// }
// devInfo.variableData = variableData;
// devInfo.variableDataCheckLastTime = now;
// devInfo.variableDataUpdated = true;
// }
// }
}

public static synchronized void searchServices(RemoteDevice remoteDevice, boolean found, long servicesSearch) {
RemoteDeviceInfo devInfo = getDevice(remoteDevice);
devInfo.serviceSearch.add(servicesSearch);
allServiceSearch.add(servicesSearch);
}

public static void discoveryInquiryFinished(long discoveryInquiry) {
deviceInquiryDuration.add(discoveryInquiry);
}

public static long allAvgDeviceInquiryDurationSec() {
return deviceInquiryDuration.avgSec();
}

public static long allAvgServiceSearchDurationSec() {
return allServiceSearch.avgSec();
}

public long avgDiscoveryFrequencySec() {
return deviceDiscovery.avgSec();
}

public long avgServiceDiscoveryFrequencySec() {
return serviceDiscovered.avgSec();
}

public long avgServiceSearchDurationSec() {
return serviceSearch.durationMaxSec();
}

public long serviceSearchSuccessPrc() {
if ((serviceSearch.count) == 0) {
return 0;
}
return (100 * serviceDiscovered.count) / (serviceSearch.count);
}

public static void saveServiceURL(ServiceRecord serviceRecord) {
services.put(serviceRecord.getConnectionURL(Configuration.getRequiredSecurity(), false), serviceRecord);
}
}

Change log

r2966 by skarzhevskyy on Mar 26, 2009   Diff
tests
Go to: 
Project members, sign in to write a code review

Older revisions

r2471 by skarzhevskyy on Nov 30, 2008   Diff
Change license to Apache License,
Version 2.0, Update headers
r2408 by skarzhevskyy on Oct 9, 2008   Diff
organize product to modules
r1493 by skarzhevskyy on Jan 7, 2008   Diff
Sort list of devices
All revisions of this file

File info

Size: 6481 bytes, 190 lines

File properties

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