Repository navigation
Expand file tree
/
Copy pathDeviceinfo.java
More file actions
148 lines (126 loc) · 3.49 KB
/
Copy pathDeviceinfo.java
File metadata and controls
148 lines (126 loc) · 3.49 KB
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
package org.androidtown.identifyinglocation;
import android.util.Log;
import java.util.Iterator;
import java.util.LinkedList;
import static java.lang.StrictMath.abs;
import static java.lang.StrictMath.pow;
/**
* Created by user on 2015-05-03.
*/
public class Deviceinfo {
String Mac_address = "";
double Rssi_value = 0;
double distance = 0.0;
int ListSize = 0;
double thresholds[] = {-49.48, -52.52, -55.02, -56.95, -58.54, -59.88, -61.04, -62.97, -65.90, -69, -72.52};
LinkedList<Integer> mlist = new LinkedList<>();
public Deviceinfo(String mac_address) {
setMac_address(mac_address);
}
public boolean addValue(int val) {
mlist.add(val);
if(mlist.size() > 50) {
this.ListSize = mlist.size();
}
return mlist.size() > 50;
}
/*
public int getRssi_value() {
int Av_M = 0;
int gap = 0;
int temp;
Iterator<Integer> it = mlist.iterator();
while(it.hasNext()){
Av_M += it.next();
}
Av_M /= mlist.size();
it = mlist.iterator();
while(it.hasNext()){
gap = abs(Av_M - it.next());
if (gap >= 3) {
it.remove();
}
}
if(mlist.size()==10 ||mlist.size()==0){
Log.d("OnLeScan", "Moving Average Value" + Av_M + "\n");
mlist.clear();
return Av_M;
}else{
Av_M=0;
it = mlist.iterator();
while(it.hasNext()){
Av_M += it.next();
}
Log.d("OnLeScan", "Moving Average Value" + Av_M/ mlist.size() + "\n");
temp = mlist.size();
mlist.clear();
return Av_M /=temp;
}
}
*/
public int getRssi_value() {
int Av_M = 0;
Iterator<Integer> it = mlist.iterator();
while(it.hasNext()){
Av_M += it.next();
}
Av_M /= mlist.size();
mlist.clear();
return Av_M;
/*
it = mlist.iterator();
while(it.hasNext()){
gap = abs(Av_M - it.next());
if (gap >= 3) {
it.remove();
}
}*/
/*if(mlist.size()==10 ||mlist.size()==0){
Log.d("OnLeScan", "Moving Average Value" + Av_M + "\n");
mlist.clear();
return Av_M;*/
//if(){
/* Av_M=0;
it = mlist.iterator();
while(it.hasNext()){
Av_M += it.next();
}
*/
// temp = mlist.size();
// Log.d("OnLeScan", "size" + temp + "\n");
// mlist.clear();
//if(temp > 0)
// return Av_M / temp;
//else
// return pre;
}
public String getMac_address() {
return Mac_address;
}
public void setMac_address(String mac_address) {
this.Mac_address = mac_address;
}
public double getDistance() {
return distance;
}
public void setDistance(double rssiFilter_value) {
double d;
double min_gap =0.0;
double candidate=0.0;
candidate = thresholds[0];
min_gap = abs(rssiFilter_value - candidate);
for(int i=1; i<11; i++)
{
if(abs(rssiFilter_value - thresholds[i]) < min_gap)
{
candidate = thresholds[i];
min_gap = abs(rssiFilter_value - candidate);
}
}
rssiFilter_value = candidate;
Log.d("rssi","++++" + rssiFilter_value);
d = pow(10.0,(-51.0 - rssiFilter_value)/20.0);
Log.d("Distance Calculate", "거리계산 : " + d + "\n");
this.distance = d;
}
}