|
|
|
@@ -4,11 +4,10 @@ import ( |
|
|
|
"context" |
|
|
|
"encoding/json" |
|
|
|
"fmt" |
|
|
|
"math" |
|
|
|
"strconv" |
|
|
|
"time" |
|
|
|
|
|
|
|
"github.com/AFASystems/presence/internal/pkg/common/appcontext" |
|
|
|
"github.com/AFASystems/presence/internal/pkg/common/utils" |
|
|
|
"github.com/AFASystems/presence/internal/pkg/config" |
|
|
|
"github.com/AFASystems/presence/internal/pkg/kafkaclient" |
|
|
|
"github.com/AFASystems/presence/internal/pkg/model" |
|
|
|
@@ -163,13 +162,12 @@ func assignBeaconToList(adv model.BeaconAdvertisement, appState *appcontext.AppS |
|
|
|
now := time.Now().Unix() |
|
|
|
|
|
|
|
if !ok { |
|
|
|
appState.UpdateLatestBeacon(id, model.Beacon{ID: id, BeaconType: adv.BeaconType, LastSeen: now, IncomingJSON: adv, BeaconLocation: adv.Hostname, Distance: getBeaconDistance(adv)}) |
|
|
|
appState.UpdateLatestBeacon(id, model.Beacon{ID: id, BeaconType: adv.BeaconType, LastSeen: now, IncomingJSON: adv, BeaconLocation: adv.Hostname, Distance: utils.CalculateDistance(adv)}) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
settings := appState.GetSettingsValue() |
|
|
|
|
|
|
|
fmt.Println("RSSI: ", adv.RSSI) |
|
|
|
if settings.RSSIEnforceThreshold && (int64(adv.RSSI) < settings.RSSIMinThreshold) { |
|
|
|
return |
|
|
|
} |
|
|
|
@@ -189,7 +187,7 @@ func assignBeaconToList(adv model.BeaconAdvertisement, appState *appcontext.AppS |
|
|
|
} |
|
|
|
|
|
|
|
metric := model.BeaconMetric{ |
|
|
|
Distance: getBeaconDistance(adv), |
|
|
|
Distance: utils.CalculateDistance(adv), |
|
|
|
Timestamp: now, |
|
|
|
RSSI: int64(adv.RSSI), |
|
|
|
Location: adv.Hostname, |
|
|
|
@@ -204,19 +202,3 @@ func assignBeaconToList(adv model.BeaconAdvertisement, appState *appcontext.AppS |
|
|
|
|
|
|
|
appState.UpdateBeacon(id, beacon) |
|
|
|
} |
|
|
|
|
|
|
|
func getBeaconDistance(adv model.BeaconAdvertisement) float64 { |
|
|
|
ratio := float64(adv.RSSI) * (1.0 / float64(twosComp(adv.TXPower))) |
|
|
|
distance := 100.0 |
|
|
|
if ratio < 1.0 { |
|
|
|
distance = math.Pow(ratio, 10) |
|
|
|
} else { |
|
|
|
distance = (0.89976)*math.Pow(ratio, 7.7095) + 0.111 |
|
|
|
} |
|
|
|
return distance |
|
|
|
} |
|
|
|
|
|
|
|
func twosComp(inp string) int64 { |
|
|
|
i, _ := strconv.ParseInt("0x"+inp, 0, 64) |
|
|
|
return i - 256 |
|
|
|
} |