Skip to content

Commit

Permalink
Merge pull request #621 from AltBeacon/fix-running-average-rssi-seria…
Browse files Browse the repository at this point in the history
…lization

Fix missing runningAverageRssi values
  • Loading branch information
davidgyoung authored Dec 13, 2017
2 parents e424793 + 300f6c2 commit e20226d
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Bug Fixes:
- Fix performance problems when using identifiers 3-15 bytes caused by
Identifier#toHexString(). (#615, David G. Young)
- Restore missing runningAverageRssi values (#621, David G. Young)
- Fix regression with `RunningAverageRssiFilter.setSampleExpirationMilliseconds`
being overwritten when committing ranged beacon measurements. (#629, Aaron Kromer)

Expand Down
1 change: 0 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ machine:
dependencies:
pre:
- echo y | android update sdk --no-ui --all --filter "tools,android-26,build-tools-26.0.2,platform-tools,extra-android-m2repository,extra-google-m2repository"

general:
branches:
ignore:
50 changes: 50 additions & 0 deletions src/main/java/org/altbeacon/beacon/Beacon.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ public class Beacon implements Parcelable, Serializable {
*/
protected String mBluetoothAddress;

/**
* The number of rssi samples available, if known
*/
private int mRssiMeasurementCount = 0;

/**
* The number of packets detected in the last cycle
*/
private int mPacketCount = 0;

/**
* If multiple RSSI samples were available, this is the running average
*/
Expand Down Expand Up @@ -244,6 +254,9 @@ protected Beacon(Parcel in) {
mBluetoothName = in.readString();
mParserIdentifier = in.readString();
mMultiFrameBeacon = in.readByte() != 0;
mRunningAverageRssi = (Double) in.readValue(null);
mRssiMeasurementCount = in.readInt();
mPacketCount = in.readInt();
}

/**
Expand All @@ -257,6 +270,8 @@ protected Beacon(Beacon otherBeacon) {
mExtraDataFields = new ArrayList<>(otherBeacon.mExtraDataFields);
this.mDistance = otherBeacon.mDistance;
this.mRunningAverageRssi = otherBeacon.mRunningAverageRssi;
this.mPacketCount = otherBeacon.mPacketCount;
this.mRssiMeasurementCount = otherBeacon.mRssiMeasurementCount;
this.mRssi = otherBeacon.mRssi;
this.mTxPower = otherBeacon.mTxPower;
this.mBluetoothAddress = otherBeacon.mBluetoothAddress;
Expand All @@ -275,6 +290,38 @@ protected Beacon() {
mExtraDataFields = new ArrayList<Long>(1);
}


/**
* Sets the measurement count that went into the rssi sample
* @param rssiMeasurementCount
*/
public void setRssiMeasurementCount(int rssiMeasurementCount) {
mRssiMeasurementCount = rssiMeasurementCount;
}

/**
* Returns the number of packet detections in the last ranging cycle
*/
public int getPacketCount() {
return mPacketCount;
}

/**
* Sets the packet detections in the last ranging cycle
* @param packetCount
*/
public void setPacketCount(int packetCount) {
mPacketCount = packetCount;
}

/**
* Returns the number of packet detections that went in to the runningAverageRssi, if known.
* If not known or inapplicable for the rssi filter used, this is zero.
*/
public int getMeasurementCount() {
return mRssiMeasurementCount;
}

/**
* Sets the running average rssi for use in distance calculations
* @param rssi the running average rssi
Expand Down Expand Up @@ -584,6 +631,9 @@ public void writeToParcel(Parcel out, int flags) {
out.writeString(mBluetoothName);
out.writeString(mParserIdentifier);
out.writeByte((byte) (mMultiFrameBeacon ? 1: 0));
out.writeValue(mRunningAverageRssi);
out.writeInt(mRssiMeasurementCount);
out.writeInt(mPacketCount);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public void addMeasurement(Integer rssi) {
LogManager.d(TAG, "armaMeasurement: %s", armaMeasurement);
}

@Override
public int getMeasurementCount() { return 0; }

public boolean noMeasurementsAvailable() {
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/altbeacon/beacon/service/RangedBeacon.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ public class RangedBeacon implements Serializable {
protected long lastTrackedTimeMillis = 0;
Beacon mBeacon;
protected transient RssiFilter mFilter = null;
private int packetCount = 0;

public RangedBeacon(Beacon beacon) {
updateBeacon(beacon);
}

public void updateBeacon(Beacon beacon) {
packetCount += 1;
mBeacon = beacon;
addMeasurement(mBeacon.getRssi());
}
Expand All @@ -48,11 +50,14 @@ public void commitMeasurements() {
if (!getFilter().noMeasurementsAvailable()) {
double runningAverage = getFilter().calculateRssi();
mBeacon.setRunningAverageRssi(runningAverage);
mBeacon.setRssiMeasurementCount(getFilter().getMeasurementCount());
LogManager.d(TAG, "calculated new runningAverageRssi: %s", runningAverage);
}
else {
LogManager.d(TAG, "No measurements available to calculate running average");
}
mBeacon.setPacketCount(packetCount);
packetCount = 0;
}

public void addMeasurement(Integer rssi) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/altbeacon/beacon/service/RssiFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public interface RssiFilter {
public void addMeasurement(Integer rssi);
public boolean noMeasurementsAvailable();
public double calculateRssi();
public int getMeasurementCount();

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public boolean noMeasurementsAvailable() {
return mMeasurements.size() == 0;
}


@Override
public int getMeasurementCount() { return mMeasurements.size(); }

@Override
public double calculateRssi() {
refreshMeasurements();
Expand Down

0 comments on commit e20226d

Please sign in to comment.