node ranging → show calculated position and diffs
This commit is contained in:
parent
35a8b17b48
commit
79dff87ce1
4 changed files with 64 additions and 1 deletions
|
@ -269,6 +269,22 @@ class MeshConsumer(AsyncWebsocketConsumer):
|
|||
})
|
||||
print("MESH %s: [%s] %s" % (self.uplink.node, address, text))
|
||||
|
||||
async def check_ota(self, addresses):
|
||||
recipients = await self.get_nodes_with_ota(addresses)
|
||||
for address, recipient in recipients.items():
|
||||
if not recipient:
|
||||
continue
|
||||
await self.check_ota_recipient(address, recipient)
|
||||
|
||||
@database_sync_to_async
|
||||
def get_nodes_with_ota(self, addresses) -> dict:
|
||||
return {node.address: node.current_ota
|
||||
for node in MeshNode.objects.filter(address__in=addresses).prefetch_ota()}
|
||||
|
||||
async def check_ota_recipient(self, address, update):
|
||||
print('checking OTA recipient', address, update)
|
||||
pass
|
||||
|
||||
async def add_dst_nodes(self, nodes=None, addresses=None):
|
||||
nodes = list(nodes) if nodes else []
|
||||
addresses = set(addresses) if addresses else set()
|
||||
|
@ -299,6 +315,8 @@ class MeshConsumer(AsyncWebsocketConsumer):
|
|||
)
|
||||
)
|
||||
|
||||
await self.check_ota([address])
|
||||
|
||||
@database_sync_to_async
|
||||
def _add_destination(self, address):
|
||||
with transaction.atomic():
|
||||
|
@ -406,8 +424,24 @@ class MeshUIConsumer(AsyncJsonWebsocketConsumer):
|
|||
else:
|
||||
if value != filter_value:
|
||||
return
|
||||
if data["msg"]["msg_type"] == MeshMessageType.LOCATE_RANGE_RESULTS.name:
|
||||
data = data.copy()
|
||||
location = await self.locator(data["msg"])
|
||||
data["position"] = None if not location else (int(location.x*100), int(location.y*100), int(location.z*100))
|
||||
await self.send_json(data)
|
||||
|
||||
@database_sync_to_async
|
||||
def locator(self, msg):
|
||||
locator = RangeLocator.load()
|
||||
return locator.locate(
|
||||
{
|
||||
r["peer"]: r["distance"]
|
||||
for r in msg["ranges"]
|
||||
if r["distance"] != 0xFFFF
|
||||
},
|
||||
None
|
||||
)
|
||||
|
||||
async def disconnect(self, code):
|
||||
await self.channel_layer.group_discard("mesh_log", self.channel_name)
|
||||
await self.channel_layer.group_discard("mesh_msg_sent", self.channel_name)
|
||||
|
|
|
@ -105,6 +105,27 @@ function connect() {
|
|||
for (cell of document.querySelectorAll(`[data-range-from="${src_node}"]:not([data-range-to="${src_node}"])`)) {
|
||||
cell.innerText = "-";
|
||||
}
|
||||
cell = document.querySelector(`[data-range-location="${src_node}"]`);
|
||||
if (!cell) break;
|
||||
if (data.position) {
|
||||
cell.innerHTML = `Location (${data.position[0]}, ${data.position[1]}, ${data.position[2]})`;
|
||||
if (src_node in nodes_xyz) {
|
||||
cell.innerHTML += `<br><em>Actual: (${nodes_xyz[src_node][0]}, ${nodes_xyz[src_node][1]}, ${nodes_xyz[src_node][2]})</em>`;
|
||||
cell.innerHTML += `<br><em>Diff: (${data.position[0]-nodes_xyz[src_node][0]}, ${data.position[1]-nodes_xyz[src_node][1]}, ${data.position[2]-nodes_xyz[src_node][2]})</em>`;
|
||||
|
||||
cell.innerHTML += '<br><em>XY: '+String(Math.round(Math.sqrt(
|
||||
Math.pow(nodes_xyz[src_node][0]-data.position[0], 2) +
|
||||
Math.pow(nodes_xyz[src_node][1]-data.position[1], 2)
|
||||
)))+' // XYZ: '+String(Math.round(Math.sqrt(
|
||||
Math.pow(nodes_xyz[src_node][0]-data.position[0], 2) +
|
||||
Math.pow(nodes_xyz[src_node][1]-data.position[1], 2) +
|
||||
Math.pow(nodes_xyz[src_node][2]-data.position[2], 2)
|
||||
)));
|
||||
|
||||
}
|
||||
} else {
|
||||
cell.innerHTML = '';
|
||||
}
|
||||
for (var i=0;i<data.msg.ranges.length;i++) {
|
||||
let range = data.msg.ranges[i];
|
||||
peer_node = range.peer;
|
||||
|
|
|
@ -26,6 +26,13 @@
|
|||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
<tr>
|
||||
<td></td>
|
||||
{% for range_from in ranging_form.cleaned_data.range_from %}
|
||||
<td data-range-location="{{ range_from }}"></td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</table>
|
||||
{% endif %}
|
||||
|
||||
|
|
|
@ -126,7 +126,8 @@ class RangeLocator:
|
|||
y=results.x[1]/100,
|
||||
permissions=(),
|
||||
icon='my_location'
|
||||
)
|
||||
)#
|
||||
location.z = results.x[2]
|
||||
|
||||
pprint(relevant_ranges)
|
||||
print("measured ranges:", ", ".join(("%.2f" % i) for i in tuple(np_ranges[:, 3])))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue