add bluetooth and UWB parameters to RangingBeacon model

This commit is contained in:
Laura Klünder 2024-03-10 13:45:20 +01:00
parent 0fd789173a
commit 372db50224
5 changed files with 41 additions and 13 deletions

View file

@ -17,7 +17,7 @@ class Command(BaseCommand):
found_beacons.setdefault(measurement["bssid"], []).append((wifi_measurement, measurement))
# put in the ones we know
known = {r.bssid: r for r in RangingBeacon.objects.all()}
known = {r.wifi_bssid: r for r in RangingBeacon.objects.all()}
# lets go through them
for bssid, measurements in found_beacons.items():

View file

@ -482,12 +482,40 @@ class RangingBeacon(SpaceGeometryMixin, models.Model):
A ranging beacon
"""
geometry = GeometryField('point')
bssid = models.CharField(_('BSSID'), max_length=17, unique=True,
node_number = models.PositiveSmallIntegerField(_('Node Number'), unique=True, null=True, blank=True)
wifi_bssid = models.CharField(_('WiFi BSSID'), unique=True, null=True, blank=True,
max_length=17,
validators=[RegexValidator(
regex='^([a-f0-9]{2}:){5}[a-f0-9]{2}$',
message='Must be a lower-case bssid',
code='invalid_bssid'
)])
)],
help_text=_("uses node's value if not set"))
bluetooth_address = models.CharField(_('Bluetooth Address'), unique=True, null=True, blank=True,
max_length=17,
validators=[RegexValidator(
regex='^([a-f0-9]{2}:){5}[a-f0-9]{2}$',
message='Must be a lower-case mac address',
code='invalid_bluetooth_address'
)],
help_text=_("uses node's value if not set"))
ibeacon_uuid = models.UUIDField(_('iBeacon UUID'), null=True, blank=True,
help_text=_("uses node's value if not set"))
ibeacon_major = models.PositiveIntegerField(_('iBeacon major value'), null=True, blank=True,
help_text=_("uses node's value if not set"))
ibeacon_minor = models.PositiveIntegerField(_('iBeacon minor value'), null=True, blank=True,
help_text=_("uses node's value if not set"))
uwb_address = models.CharField(_('UWB Address'), unique=True, null=True, blank=True,
max_length=23,
validators=[RegexValidator(
regex='^([a-f0-9]{2}:){7}[a-f0-9]{2}$',
message='Must be a lower-case 8-byte UWB address',
code='invalid_uwb_address'
)],
help_text=_("uses node's value if not set"))
altitude = models.DecimalField(_('altitude above ground'), max_digits=6, decimal_places=2, default=0,
validators=[MinValueValidator(Decimal('0'))])
comment = models.TextField(null=True, blank=True, verbose_name=_('comment'))
@ -508,5 +536,5 @@ class RangingBeacon(SpaceGeometryMixin, models.Model):
@property
def title(self):
if self.comment:
return f'{self.bssid} ({self.comment})'
return self.bssid
return f'{self.wifi_bssid} ({self.comment})'
return self.wifi_bssid

View file

@ -189,7 +189,7 @@ def firmware_upload(request, firmware_data: UploadFirmwareSchema, binary_files:
build = version.builds.create(
variant=build_data.variant,
chip=image.ext_header.chip,
chip=image.ext_header.chip.c_value,
sha256_hash=image.app_desc.app_elf_sha256,
project_description=build_data.project_description,
binary=binary_files_by_name[build_data.uploaded_filename],

View file

@ -186,7 +186,7 @@ class MeshNodeQuerySet(models.QuerySet):
try:
for ranging_beacon in RangingBeacon.objects.filter(bssid__in=nodes.keys()).select_related('space'):
# noinspection PyUnresolvedReferences
nodes[ranging_beacon.bssid]._ranging_beacon = ranging_beacon
nodes[ranging_beacon.wifi_bssid]._ranging_beacon = ranging_beacon
for node in nodes.values():
if not hasattr(node, "_ranging_beacon"):
node._ranging_beacon = None
@ -415,7 +415,7 @@ def firmware_upload_path(instance, filename):
class FirmwareBuild(models.Model):
CHIPS = [(chiptype.value, chiptype.pretty_name) for chiptype in ChipType]
CHIPS = [(chiptype.c_value, chiptype.pretty_name) for chiptype in ChipType]
version = models.ForeignKey(FirmwareVersion, related_name='builds', on_delete=models.CASCADE)
variant = models.CharField(_('variant name'), max_length=64)

View file

@ -70,7 +70,7 @@ class Locator:
def _rebuild(self, router):
for beacon in RangingBeacon.objects.all():
peer_id = self.get_peer_id(beacon.bssid, create=True)
peer_id = self.get_peer_id(beacon.wifi_bssid, create=True)
self.peers[peer_id].xyz = (
int(beacon.geometry.x * 100),
int(beacon.geometry.y * 100),