Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Calculates the accuracy of an RSSI reading.
     *
     * The code was taken from {@link http://stackoverflow.com/questions/20416218/understanding-ibeacon-distancing}
     *
     * @param txPower the calibrated TX power of an iBeacon
     * @param rssi the RSSI value of the iBeacon
     * @return
     */
    public static double calculateAccuracy(int txPower, double rssi) {
        if (rssi == 0) {
            return -1.0; // if we cannot determine accuracy, return -1.
        }

        double ratio = rssi * 1.0 / txPower;
        if (ratio < 1.0) {
            return Math.pow(ratio, 10);
        } else {
            final double accuracy = (0.89976) * Math.pow(ratio, 7.7095) + 0.111;
            return accuracy;
        }
    }
}