diff --git a/gui/preload-main.js b/gui/preload-main.js index 8aecdb1c..19a4cc2d 100644 --- a/gui/preload-main.js +++ b/gui/preload-main.js @@ -2895,6 +2895,15 @@ ipcRenderer.on("run-tnc-command-fec-iswriting", (event) => { }); ipcRenderer.on("run-tnc-command", (event, arg) => { + + if (arg.command == "enable_mesh") { + sock.enable_mesh(); + } + + if (arg.command == "disable_mesh") { + sock.disable_mesh(); + } + if (arg.command == "save_my_call") { sock.saveMyCall(arg.callsign); } diff --git a/gui/preload-mesh.js b/gui/preload-mesh.js index d9a5c8f8..efaf1f0b 100644 --- a/gui/preload-mesh.js +++ b/gui/preload-mesh.js @@ -17,9 +17,22 @@ window.addEventListener("DOMContentLoaded", () => { .getElementById("enable_mesh") .addEventListener("click", () => { if (document.getElementById("enable_mesh").checked) { - display_class("table-info", true); + + + let Data = { + type: "set", + command: "enable_mesh", + }; + ipcRenderer.send("run-tnc-command", Data); + + } else { - display_class("table-info", false); +let Data = { + type: "set", + command: "disable_mesh", + }; + ipcRenderer.send("run-tnc-command", Data); + } }); diff --git a/gui/sock.js b/gui/sock.js index eeb1c487..18c23e19 100644 --- a/gui/sock.js +++ b/gui/sock.js @@ -852,6 +852,21 @@ exports.sendFecIsWriting = function (mycallsign) { writeTncCommand(command); }; +// ENABLE MESH +exports.enable_mesh = function () { + command = + '{"type" : "set", "command" : "enable_mesh"}'; + writeTncCommand(command); +}; + +// DISABLE MESH +exports.disable_mesh = function () { + command = + '{"type" : "set", "command" : "disable_mesh"}'; + writeTncCommand(command); +}; + + // SEND FEC TO BROADCASTCHANNEL exports.sendBroadcastChannel = function (channel, data_out, uuid) { let checksum = ""; diff --git a/gui/src/mesh-module.html b/gui/src/mesh-module.html index 10c261ce..f30139b5 100644 --- a/gui/src/mesh-module.html +++ b/gui/src/mesh-module.html @@ -26,7 +26,7 @@ class="btn-check" id="enable_mesh" autocomplete="off" - checked + /> 14 28 42 ==> 3 mesh routing entries - # callsign_crc(3), router_crc(3), hops(1), path_score(1) == 8 --> 6 - # callsign_crc(3), hops(1), path_score(1) == 5 --> 10 + # callsign(6), router(6), hops(1), path_score(1) == 14 ==> 14 28 42 ==> 3 mesh routing entries + # callsign_crc(3), router_crc(3), hops(1), path_score(1) == 8 --> 6 + # callsign_crc(3), hops(1), path_score(1) == 5 --> 10 - # Create a new bytearray with a fixed length of 50 - result = bytearray(50) + # Create a new bytearray with a fixed length of 50 + result = bytearray(50) - # Iterate over the route subarrays and add the selected entries to the result bytearray - index = 0 - for route_id, route in enumerate(MeshParam.routing_table): - # the value 5 is the length of crc24 + hops + score + # Iterate over the route subarrays and add the selected entries to the result bytearray + index = 0 + for route_id, route in enumerate(MeshParam.routing_table): + # the value 5 is the length of crc24 + hops + score - dxcall = MeshParam.routing_table[route_id][0] - # router = MeshParam.routing_table[i][1] - hops = MeshParam.routing_table[route_id][2] - # snr = MeshParam.routing_table[i][3] - route_score = np.clip(MeshParam.routing_table[route_id][4], 0, 254) - # timestamp = MeshParam.routing_table[i][5] - result[index:index + 5] = dxcall + bytes([hops]) + bytes([route_score]) - index += 5 + dxcall = MeshParam.routing_table[route_id][0] + # router = MeshParam.routing_table[i][1] + hops = MeshParam.routing_table[route_id][2] + # snr = MeshParam.routing_table[i][3] + route_score = np.clip(MeshParam.routing_table[route_id][4], 0, 254) + # timestamp = MeshParam.routing_table[i][5] + result[index:index + 5] = dxcall + bytes([hops]) + bytes([route_score]) + index += 5 - print(len(result)) - # Split the result bytearray into a list of fixed-length bytearrays - split_result = [result[i:i + 50] for i in range(0, len(result), 50)] - print(len(split_result)) - frame_list = [] - for _ in split_result: - # make sure payload is always 50 - _[len(_):] = bytes(50 - len(_)) - #print(len(_)) - frame_list.append(mesh_broadcast_frame_header + _) + print(len(result)) + # Split the result bytearray into a list of fixed-length bytearrays + split_result = [result[i:i + 50] for i in range(0, len(result), 50)] + print(len(split_result)) + frame_list = [] + for _ in split_result: + # make sure payload is always 50 + _[len(_):] = bytes(50 - len(_)) + #print(len(_)) + frame_list.append(mesh_broadcast_frame_header + _) - print(frame_list) - TNC.transmitting = True - c2_mode = FREEDV_MODE.datac4.value - modem.MODEM_TRANSMIT_QUEUE.put([c2_mode, 1, 0, frame_list]) + print(frame_list) + TNC.transmitting = True + c2_mode = FREEDV_MODE.datac4.value + modem.MODEM_TRANSMIT_QUEUE.put([c2_mode, 1, 0, frame_list]) + + # Wait while transmitting + while TNC.transmitting: + threading.Event().wait(0.01) + except Exception as e: + self.log.warning("[MESH] broadcasting routing table", e=e) - # Wait while transmitting - while TNC.transmitting: - threading.Event().wait(0.01) - except Exception as e: - self.log.warning("[MESH] broadcasting routing table", e=e) def mesh_rx_dispatcher(self): while True: diff --git a/tnc/sock.py b/tnc/sock.py index 03163748..714220ea 100644 --- a/tnc/sock.py +++ b/tnc/sock.py @@ -395,6 +395,13 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): if received_json["type"] == "get" and received_json["command"] == "routing_table": self.tnc_get_mesh_routing_table(received_json) + # ENABLE MESH + if received_json["type"] == "set" and received_json["command"] == "enable_mesh": + MeshParam.enable_protocol = True + + # DISABLE MESH + if received_json["type"] == "set" and received_json["command"] == "disable_mesh": + MeshParam.enable_protocol = False except Exception as err: log.error("[SCK] JSON decoding error", e=err) diff --git a/tnc/static.py b/tnc/static.py index 17b7cf73..b75a6cc1 100644 --- a/tnc/static.py +++ b/tnc/static.py @@ -93,6 +93,7 @@ class HamlibParam: @dataclass class MeshParam: routing_table = [] + enable_protocol = False @dataclass class ModemParam: tuning_range_fmin: float = -50.0