initial work on mesh prototype

This commit is contained in:
DJ2LS 2023-05-24 09:00:54 +02:00
parent 55a28c79ed
commit c174a543fd
3 changed files with 74 additions and 3 deletions

View file

@ -8,10 +8,11 @@ import time
from datetime import datetime,timezone
import crcengine
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 numpy as np
import threading
import mesh
log = structlog.get_logger("helpers")
@ -164,7 +165,8 @@ def add_to_heard_stations(dxcallsign, dxgrid, datatype, snr, offset, frequency):
]
)
break
# trigger update of routing table
mesh.MeshRouter.get_from_heard_stations()
# for idx, item in enumerate(TNC.heard_stations):
# if dxcallsign in item:

66
tnc/mesh.py Normal file
View file

@ -0,0 +1,66 @@
# -*- coding: UTF-8 -*-
"""
@author: DJ2LS
HF mesh networking prototype and testing module
import time
MeshParam.routing_table = [['AA1AA', 'direct', 0, 1.0, 25, time.time(), ], ['AA1AA', 'AA2BB', 1, 3.1, 10, time.time(), ],
['AA3CC', 'AA2BB', 5, -4.5, -3, time.time(), ]]
print(MeshParam.routing_table)
print("---------------------------------")
"""
# pylint: disable=invalid-name, line-too-long, c-extension-no-member
# pylint: disable=import-outside-toplevel, attribute-defined-outside-init
from static import TNC, MeshParam
import time
import threading
class MeshRouter():
def get_from_heard_stations(self):
"""
get data from heard stations
heard stations format:
[dxcallsign,dxgrid,int(time.time()),datatype,snr,offset,frequency]
TNC.heard_stations.append(
[
dxcallsign,
dxgrid,
int(time.time()),
datatype,
snr,
offset,
frequency,
]
)
"""
dxcallsign = 0
dxgrid = 1
timestamp = 2
type = 3
snr = 4
offset = 5
frequency = 6
for item in TNC.heard_stations:
new_router = [item[dxcallsign], 'direct', 0, item[snr], item[snr], item[timestamp]]
self.add_router_to_routing_table(new_router)
def add_router_to_routing_table(self, new_router):
# destination callsign # router callsign # hops # rx snr # route quality # timestamp
for _, item in enumerate(MeshParam.routing_table):
# update routing entry if exists
if new_router[0] in item[0] and new_router[1] in item[1]:
print(f"UPDATE {MeshParam.routing_table[_]} >>> {new_router}")
MeshParam.routing_table[_] = new_router
# add new routing entry if not exists
if new_router not in MeshParam.routing_table:
MeshParam.routing_table.append(new_router)

View file

@ -92,7 +92,10 @@ class HamlibParam:
hamlib_mode: str = ""
hamlib_rf: int = 0
@dataclass
@dataclass
class MeshParam:
routing_table = []
@dataclass
class ModemParam:
tuning_range_fmin: float = -50.0
tuning_range_fmax: float = 50.0