get routing table via network

This commit is contained in:
DJ2LS 2023-05-28 12:13:19 +02:00
parent e75c92c27c
commit be4d158c37

View file

@ -27,7 +27,7 @@ import time
import wave import wave
import helpers import helpers
import static import static
from static import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, TNC from static import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, TNC, MeshParam
import structlog import structlog
from random import randrange from random import randrange
import ujson as json import ujson as json
@ -391,6 +391,11 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
else: else:
self.tnc_set_mode(received_json) self.tnc_set_mode(received_json)
# GET ROUTING TABLE
if received_json["type"] == "get" and received_json["command"] == "routing_table":
self.tnc_get_mesh_routing_table(received_json)
except Exception as err: except Exception as err:
log.error("[SCK] JSON decoding error", e=err) log.error("[SCK] JSON decoding error", e=err)
@ -761,6 +766,40 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
"[SCK] STOP command execution error", e=err, command=received_json "[SCK] STOP command execution error", e=err, command=received_json
) )
def tnc_get_mesh_routing_table(self, received_json):
try:
if not RX_BUFFER.empty():
output = {
"command": "routing_table",
"routes": [],
}
for route in range(MeshParam.routing_table):
output["routes"].append(
{
"dxcall": MeshParam.routing_table[route][0],
"router": MeshParam.routing_table[route][1],
"hops": MeshParam.routing_table[route][2],
"snr": MeshParam.routing_table[route][3],
"score": MeshParam.routing_table[route][4],
"timestamp": MeshParam.routing_table[route][5],
}
)
jsondata = json.dumps(output)
# self.request.sendall(bytes(jsondata, encoding))
SOCKET_QUEUE.put(jsondata)
command_response("routing_table", True)
except Exception as err:
command_response("routing_table", False)
log.warning(
"[SCK] Send RX buffer command execution error",
e=err,
command=received_json,
)
def tnc_get_rx_buffer(self, received_json): def tnc_get_rx_buffer(self, received_json):
try: try:
if not RX_BUFFER.empty(): if not RX_BUFFER.empty():