make linter happy

This commit is contained in:
Laura Klünder 2023-10-06 02:46:43 +02:00
parent 79cde0f78c
commit b732d52f65
21 changed files with 82 additions and 75 deletions

View file

@ -1,8 +1,8 @@
import re
import struct
from abc import ABC, abstractmethod
from dataclasses import dataclass, fields, field, Field
from typing import Any, Sequence, Self
from dataclasses import Field, dataclass, fields
from typing import Any, Self, Sequence
from c3nav.mesh.utils import indent_c

View file

@ -1,15 +1,15 @@
import traceback
from asgiref.sync import async_to_sync
from channels.generic.websocket import WebsocketConsumer, JsonWebsocketConsumer
from channels.generic.websocket import JsonWebsocketConsumer, WebsocketConsumer
from django.utils import timezone
from c3nav.mesh.utils import get_mesh_comm_group
from c3nav.mesh import messages
from c3nav.mesh.messages import MeshMessage, MESH_BROADCAST_ADDRESS, MeshMessageType, MESH_ROOT_ADDRESS, \
MESH_NONE_ADDRESS
from c3nav.mesh.messages import (MESH_BROADCAST_ADDRESS, MESH_NONE_ADDRESS, MESH_ROOT_ADDRESS, MeshMessage,
MeshMessageType)
from c3nav.mesh.models import MeshNode, NodeMessage
from c3nav.mesh.tasks import send_channel_msg
from c3nav.mesh.utils import get_mesh_comm_group
# noinspection PyAttributeOutsideInit
@ -34,8 +34,8 @@ class MeshConsumer(WebsocketConsumer):
self.remove_dst_nodes(self.dst_nodes)
def send_msg(self, msg, sender=None, exclude_uplink_address=None):
#print("sending", msg, MeshMessage.encode(msg).hex(' ', 1))
#self.log_text(msg.dst, "sending %s" % msg)
# print("sending", msg, MeshMessage.encode(msg).hex(' ', 1))
# self.log_text(msg.dst, "sending %s" % msg)
self.send(bytes_data=MeshMessage.encode(msg))
async_to_sync(self.channel_layer.group_send)("mesh_msg_sent", {
"type": "mesh.msg_sent",
@ -44,7 +44,7 @@ class MeshConsumer(WebsocketConsumer):
"sender": sender,
"uplink": self.uplink_node.address if self.uplink_node else None,
"recipient": msg.dst,
#"msg": msg.tojson(), # not doing this part for privacy reasons
# "msg": msg.tojson(), # not doing this part for privacy reasons
})
def receive(self, text_data=None, bytes_data=None):
@ -81,7 +81,7 @@ class MeshConsumer(WebsocketConsumer):
print('it\'s a broadcast so it\'s also for us')
self.log_text(MESH_ROOT_ADDRESS, "received broadcast message, forwarding and handling...")
#print('Received message:', msg)
# print('Received message:', msg)
src_node, created = MeshNode.objects.get_or_create(address=msg.src)

View file

@ -1,7 +1,7 @@
from dataclasses import dataclass, field
from enum import IntEnum, unique
from c3nav.mesh.baseformats import FixedHexFormat, VarArrayFormat, StructType, SimpleFormat, FixedStrFormat
from c3nav.mesh.baseformats import FixedHexFormat, FixedStrFormat, SimpleFormat, StructType, VarArrayFormat
class MacAddressFormat(FixedHexFormat):
@ -14,7 +14,6 @@ class MacAddressesListFormat(VarArrayFormat):
super().__init__(child_type=MacAddressFormat())
@unique
class LedType(IntEnum):
SERIAL = 1
@ -56,4 +55,4 @@ class FirmwareAppDescription(StructType, no_c_type=True):
compile_date: str = field(metadata={"format": FixedStrFormat(16)})
idf_version: str = field(metadata={"format": FixedStrFormat(32)})
app_elf_sha256: str = field(metadata={"format": FixedHexFormat(32)})
reserv2: list[int] = field(metadata={"format": SimpleFormat('20I')}, repr=False)
reserv2: list[int] = field(metadata={"format": SimpleFormat('20I')}, repr=False)

View file

@ -7,7 +7,7 @@ from django.http import Http404
from django.utils.translation import gettext_lazy as _
from c3nav.mesh.dataformats import LedConfig
from c3nav.mesh.messages import MeshMessageType, MeshMessage, MESH_ROOT_ADDRESS, MESH_BROADCAST_ADDRESS
from c3nav.mesh.messages import MESH_BROADCAST_ADDRESS, MESH_ROOT_ADDRESS, MeshMessage, MeshMessageType
from c3nav.mesh.models import MeshNode
@ -197,4 +197,4 @@ class ConfigPositionMessageForm(MeshMessageForm):
class MeshNodeForm(forms.ModelForm):
class Meta:
model = MeshNode
fields = ["name"]
fields = ["name"]

View file

@ -2,9 +2,8 @@ from dataclasses import fields
from django.core.management.base import BaseCommand
from c3nav.mesh.dataformats import LedConfig
from c3nav.mesh.baseformats import normalize_name
from c3nav.mesh.messages import MeshMessage, MeshMessageType
from c3nav.mesh.messages import MeshMessage
from c3nav.mesh.utils import indent_c
@ -43,7 +42,8 @@ class Command(BaseCommand):
struct_lines[base_name] = "%s %s;" % (name, base_name.replace('_announce', ''))
struct_sizes.append(size)
print(code)
print("static_assert(sizeof(%s) == %d, \"size of generated message structs is calculated wrong\");" % (name, size))
print("static_assert(sizeof(%s) == %d, \"size of generated message structs is calculated wrong\");" %
(name, size))
print()
else:
nodata.add(msg_type)
@ -53,7 +53,10 @@ class Command(BaseCommand):
for line in struct_lines.values():
print(indent_c(line))
print("} mesh_msg_data_t; ")
print("static_assert(sizeof(mesh_msg_data_t) == %d, \"size of generated message structs is calculated wrong\");" % max(struct_sizes))
print(
"static_assert(sizeof(mesh_msg_data_t) == %d, \"size of generated message structs is calculated wrong\");"
% max(struct_sizes)
)
max_msg_type = max(MeshMessage.get_types().keys())
macro_data = []

View file

@ -1,17 +1,15 @@
import re
from dataclasses import asdict, dataclass, field, fields, is_dataclass
from dataclasses import dataclass, field
from enum import IntEnum, unique
from itertools import chain
from typing import TypeVar
import channels
from asgiref.sync import async_to_sync
from c3nav.mesh.utils import get_mesh_comm_group, indent_c
from c3nav.mesh.dataformats import (LedConfig, LedConfig,
MacAddressesListFormat, MacAddressFormat, RangeItemType, FirmwareAppDescription)
from c3nav.mesh.baseformats import SimpleFormat, BoolFormat, FixedStrFormat, FixedHexFormat, VarArrayFormat, \
VarStrFormat, StructType
from c3nav.mesh.baseformats import BoolFormat, FixedStrFormat, SimpleFormat, StructType, VarArrayFormat, VarStrFormat
from c3nav.mesh.dataformats import (FirmwareAppDescription, LedConfig, MacAddressesListFormat, MacAddressFormat,
RangeItemType)
from c3nav.mesh.utils import get_mesh_comm_group
MESH_ROOT_ADDRESS = '00:00:00:00:00:00'
MESH_NONE_ADDRESS = '00:00:00:00:00:00'
@ -20,6 +18,7 @@ MESH_CHILDREN_ADDRESS = '00:00:00:00:ff:ff'
MESH_BROADCAST_ADDRESS = 'ff:ff:ff:ff:ff:ff'
NO_LAYER = 0xFF
@unique
class MeshMessageType(IntEnum):
NOOP = 0x00
@ -273,4 +272,4 @@ class ConfigUplinkMessage(MeshMessage, msg_id=MeshMessageType.CONFIG_UPLINK):
@dataclass
class LocateReportRangeMessage(MeshMessage, msg_id=MeshMessageType.LOCATE_REPORT_RANGE):
""" report distance to given nodes """
ranges: dict[str, int] = field(metadata={"format": VarArrayFormat(RangeItemType)})
ranges: dict[str, int] = field(metadata={"format": VarArrayFormat(RangeItemType)})

View file

@ -1,12 +1,14 @@
from collections import UserDict
from functools import cached_property
from operator import attrgetter
from typing import Mapping, Self, Any
from typing import Any, Mapping, Self
from django.db import models, NotSupportedError
from django.db import NotSupportedError, models
from django.utils.translation import gettext_lazy as _
from c3nav.mesh.messages import MeshMessageType, ChipType, MeshMessage as MeshMessage
from c3nav.mesh.messages import ChipType
from c3nav.mesh.messages import MeshMessage as MeshMessage
from c3nav.mesh.messages import MeshMessageType
class MeshNodeQuerySet(models.QuerySet):
@ -42,6 +44,7 @@ class MeshNodeQuerySet(models.QuerySet):
except NotSupportedError:
pass
class LastMessagesByTypeLookup(UserDict):
def __init__(self, node):
super().__init__()