Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

51 строка
1.3 KiB

  1. package location
  2. import (
  3. "log/slog"
  4. "time"
  5. "github.com/AFASystems/presence/internal/pkg/common/appcontext"
  6. "github.com/AFASystems/presence/internal/pkg/common/utils"
  7. )
  8. // AssignBeaconToList updates app state with a new beacon advertisement: appends a metric
  9. // to the beacon's sliding window and updates last seen.
  10. func AssignBeaconToList(adv appcontext.BeaconAdvertisement, appState *appcontext.AppState) {
  11. id := adv.ID
  12. now := time.Now().Unix()
  13. settings := appState.GetSettingsValue()
  14. if settings.RSSIEnforceThreshold && int64(adv.RSSI) < settings.RSSIMinThreshold {
  15. slog.Debug("settings RSSI threshold filter", "id", id)
  16. return
  17. }
  18. beacon, ok := appState.GetBeacon(id)
  19. if !ok {
  20. beacon = appcontext.Beacon{ID: id}
  21. }
  22. beacon.IncomingJSON = adv
  23. beacon.LastSeen = now
  24. if beacon.BeaconMetrics == nil {
  25. beacon.BeaconMetrics = make([]appcontext.BeaconMetric, 0, settings.BeaconMetricSize)
  26. }
  27. metric := appcontext.BeaconMetric{
  28. Distance: utils.CalculateDistance(adv),
  29. Timestamp: now,
  30. RSSI: int64(adv.RSSI),
  31. Location: adv.Hostname,
  32. }
  33. if len(beacon.BeaconMetrics) >= settings.BeaconMetricSize {
  34. copy(beacon.BeaconMetrics, beacon.BeaconMetrics[1:])
  35. beacon.BeaconMetrics[settings.BeaconMetricSize-1] = metric
  36. } else {
  37. beacon.BeaconMetrics = append(beacon.BeaconMetrics, metric)
  38. }
  39. appState.UpdateBeacon(id, beacon)
  40. }