25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

28 satır
584 B

  1. package utils
  2. import (
  3. "math"
  4. "strconv"
  5. "github.com/AFASystems/presence/internal/pkg/model"
  6. )
  7. func CalculateDistance(adv model.BeaconAdvertisement) float64 {
  8. rssi := adv.RSSI
  9. power := adv.TXPower
  10. ratio := float64(rssi) * (1.0 / float64(twosComp(power)))
  11. distance := 100.0
  12. if ratio < 1.0 {
  13. distance = math.Pow(ratio, 10)
  14. } else {
  15. distance = (0.89976)*math.Pow(ratio, 7.7095) + 0.111
  16. }
  17. return distance
  18. }
  19. // TwosComp converts a two's complement hexadecimal string to int64
  20. func twosComp(inp string) int64 {
  21. i, _ := strconv.ParseInt("0x"+inp, 0, 64)
  22. return i - 256
  23. }