Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Function calculates the distance from a given RSSI value.
     *      RSSI                = -(10 * n)log_10(distance) - A     | + A
     *      RSSI - A            = -10n * log_10(distance)           | / -10n
     *      (RSSI - A) / -10N   = log_10(distance)
     *      10 ^(RSSI - A) / -10N) = distance
     *
     * @param currentRSSI   live value from the receiver.
     * @param A             Fix value at 1m distance.
     * @param n             Signal propagation constant.
     * @return              Distance in m.
     */
    public static double distance(double currentRSSI, double A, double n) {
        double exp = (currentRSSI - A) / (-10 * n);

        return Math.pow(10, exp);
    }
}