From 0c9b253d87dbd2beb5313e48b5086d17de2fd7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Kl=C3=BCnder?= Date: Thu, 5 Oct 2023 05:40:07 +0200 Subject: [PATCH] more features for tracing and everything --- .../control/fragment_mesh_websocket.html | 42 +++++++++++++------ .../control/mesh_message_sending.html | 32 ++++++++++---- .../control/templates/control/mesh_nodes.html | 35 +++++++++++++--- src/c3nav/control/views/mesh.py | 11 +++++ src/c3nav/mesh/forms.py | 3 +- .../mesh/management/commands/mesh_msg_c.py | 4 +- 6 files changed, 97 insertions(+), 30 deletions(-) diff --git a/src/c3nav/control/templates/control/fragment_mesh_websocket.html b/src/c3nav/control/templates/control/fragment_mesh_websocket.html index 6d266887..df7ad577 100644 --- a/src/c3nav/control/templates/control/fragment_mesh_websocket.html +++ b/src/c3nav/control/templates/control/fragment_mesh_websocket.html @@ -65,11 +65,26 @@ function connect() { break case 'mesh.msg_sent': {% if send_uuid %} - line = document.createElement("p"); - line.innerText = "sent via uplink ["+data.channel+"] "+data.uplink; + line = document.createElement("span"); + + text = document.createElement("span") + text.innerText = "sent via uplink " + line.appendChild(text) + + text = document.createElement("small") + text.innerText = "["+data.channel+"] " + line.appendChild(text) + + link_tag = document.createElement("a"); + link_tag.href = "/control/mesh/" + data.uplink; + link_tag.innerText = data.uplink; if (node_names[data.uplink]) { - line.innerText += " ("+node_names[data.uplink]+")"; + link_tag.innerText += "("+node_names[data.uplink]+")"; } + line.appendChild(link_tag); + + line.appendChild(document.createElement("br")); + document.getElementById("sending-status-"+data.recipient).appendChild(line); {% endif %} break; @@ -77,23 +92,21 @@ function connect() { case 'mesh.msg_received': {% if send_uuid and msg_type == "MESH_ROUTE_REQUEST" %} if (data.msg.route) { + line = document.createElement('tr'); + + cell = document.createElement("td"); link_tag = document.createElement("a"); link_tag.href = "/control/mesh/" + data.msg.src; link_tag.innerText = data.msg.src; if (node_names[data.msg.src]) { link_tag.innerText += " ("+node_names[data.msg.src]+")"; } + cell.appendChild(link_tag); + line.appendChild(cell); + if (data.msg.route === "00:00:00:00:00:00") { - line = document.createElement("li"); - line.appendChild(link_tag); document.getElementById("no-routes").appendChild(line); } else { - line = document.createElement("tr"); - - cell = document.createElement("td"); - cell.appendChild(link_tag); - line.appendChild(cell); - cell = document.createElement("td"); link_tag = document.createElement("a"); link_tag.href = "/control/mesh/" + data.msg.route; @@ -108,14 +121,17 @@ function connect() { } } else { for (var i=0;i {% for address, name in recipients %} - {{ address }}{% if name %} ({{ name }}){% endif %} + + {% if address != "ff:ff:ff:ff:ff:ff" %}{% endif %} + {{ address }}{% if name %} ({{ name }}){% endif %} + {% if address != "ff:ff:ff:ff:ff:ff" %}{% endif %} + {% endfor %} {% if msg_type == "MESH_ROUTE_REQUEST" %} -
+

Routes

@@ -38,13 +42,27 @@
-
-

No Route

-
    +
    +

    No Route

    + + + + + + + +
    {% trans 'Node' %}
    -
    +

    Trace

    -
      + + + + + + + +
      {% trans 'Hop' %}
      {% endif %}
      diff --git a/src/c3nav/control/templates/control/mesh_nodes.html b/src/c3nav/control/templates/control/mesh_nodes.html index 1cea8bed..6202244c 100644 --- a/src/c3nav/control/templates/control/mesh_nodes.html +++ b/src/c3nav/control/templates/control/mesh_nodes.html @@ -4,9 +4,34 @@ {% block heading %}{% trans 'Mesh' %}{% endblock %} {% block subcontent %} - - {% trans 'View messages' %} - +
      + +
      +

      Send messages

      +
      + {% csrf_token %} + + +
      +
      + +
      +

      Nodes

      @@ -21,11 +46,11 @@
      {% trans 'Node' %}{{ node }} {{ node.last_messages.CONFIG_FIRMWARE.parsed.get_chip_display }} - rev{{ node.last_messages.CONFIG_FIRMWARE.parsed.revision_major }}.{{ node.last_messages.CONFIG_FIRMWARE.parsed.revision_minor }} + rev{{ node.last_messages.CONFIG_FIRMWARE.parsed.revision_major }}.{{ node.last_messages.CONFIG_FIRMWARE.parsed.revision_minor }} {{ node.last_messages.CONFIG_FIRMWARE.parsed.version }} - (IDF {{ node.last_messages.CONFIG_FIRMWARE.parsed.idf_version }}) + (IDF {{ node.last_messages.CONFIG_FIRMWARE.parsed.idf_version }}) {% blocktrans trimmed with timesince=node.last_msg|timesince %} diff --git a/src/c3nav/control/views/mesh.py b/src/c3nav/control/views/mesh.py index b72e6a36..bfc526ef 100644 --- a/src/c3nav/control/views/mesh.py +++ b/src/c3nav/control/views/mesh.py @@ -26,6 +26,17 @@ class MeshNodeListView(ControlPanelMixin, ListView): def get_queryset(self): return super().get_queryset().annotate(last_msg=Max('received_messages__datetime')).prefetch_last_messages() + def get_context_data(self, *args, **kwargs): + return { + **super().get_context_data(*args, **kwargs), + "send_msg_types": [msg_type.name for msg_type in MeshMessageForm.msg_types.keys()], + } + + def post(self, request): + return redirect( + reverse("control.mesh_message.send", kwargs={"msg_type": request.POST.get("send_msg_type", "")}) + ) + class MeshNodeDetailView(ControlPanelMixin, DetailView): model = MeshNode diff --git a/src/c3nav/mesh/forms.py b/src/c3nav/mesh/forms.py index 64c6ee2c..2a94ebf1 100644 --- a/src/c3nav/mesh/forms.py +++ b/src/c3nav/mesh/forms.py @@ -1,6 +1,5 @@ import time from dataclasses import fields as dataclass_fields -from functools import cached_property from django import forms from django.core.exceptions import ValidationError @@ -99,7 +98,7 @@ class MeshRouteRequestForm(MeshMessageForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.fields["address"].choices = self.node_choices + self.fields["address"].choices = (('', '------'), )+self.node_choices def get_msg_data(self): return { diff --git a/src/c3nav/mesh/management/commands/mesh_msg_c.py b/src/c3nav/mesh/management/commands/mesh_msg_c.py index 36e8f6d6..36b2ac28 100644 --- a/src/c3nav/mesh/management/commands/mesh_msg_c.py +++ b/src/c3nav/mesh/management/commands/mesh_msg_c.py @@ -10,9 +10,7 @@ class Command(BaseCommand): def handle(self, *args, **options): done_struct_names = set() nodata = set() - struct_lines = { - "num": "uint8_t num; /** defined here for convenience. subtypes that use it will define it themselves */" - } + struct_lines = {} for msg_type in MeshMessage.msg_types.values(): if msg_type.c_struct_name: