Skip to content

Commit

Permalink
Merge pull request #44 from DerHirschi/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
DerHirschi authored Jan 20, 2025
2 parents cf610e7 + 832090b commit f8b369c
Show file tree
Hide file tree
Showing 38 changed files with 1,776 additions and 556 deletions.
52 changes: 33 additions & 19 deletions ax25/ax25Connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,12 @@ def _ft_queue_handling(self):

def ft_reset_timer(self, conn_uid: str):
if self.ft_obj is not None:
print(f"ft_resetRNR: conn_uid {conn_uid}")
print(f"ft_resetRNR: rev conn_uid {reverse_uid(conn_uid)}")
print(f"ft_resetRNR: self.uid {self.uid}")
if conn_uid != self.uid and reverse_uid(conn_uid) != self.uid:
print(f"ft_resetRNR:SET! ")

self.ft_obj.ft_set_wait_timer()

#######################
Expand Down Expand Up @@ -589,33 +594,41 @@ def new_link_connection(self, conn):
self.my_call_str = digi_call
# self.ax25_out_frame.digi_call = str(conn.my_call_str)
self.digi_call = digi_call
print("LC 1")
self._port_handler.link_connections[str(conn.uid)] = conn, ''
else:
self._port_handler.link_connections[str(conn.uid)] = conn, self.my_call_str
print("LC 2")
self._port_handler.link_connections[str(conn.uid)] = conn, conn.my_call_str

self.LINK_Connection = conn
self.is_link = True
# self.cli = cli.cliMain.NoneCLI(self) # Disable CLI
return True

def new_digi_connection(self, conn):
# print(f"Conn newDIGIConn: UID: {conn.uid}")
# logger.debug(f"Conn newDIGIConn: UID: {conn.uid}")
print(f"Conn newDIGIConn: UID: {conn.uid}")
logger.debug(f"Conn newDIGIConn: UID: {conn.uid}")
if conn is None:
print("Conn ERROR: newDIGIConn: not conn")
logger.error("Conn ERROR: newDIGIConn: not conn")
return False
if self.uid in self._port_handler.link_connections.keys():
if self.uid in list(self._port_handler.link_connections.keys()):
self.zustand_exec.change_state(4)
self.zustand_exec.tx(None)
print("Conn ERROR: newDIGIConn: self.uid in self._port_handler.link_connections")
logger.error("Conn ERROR: newDIGIConn: self.uid in self._port_handler.link_connections")
logger.error(f"{self.uid} - {self._port_handler.link_connections.keys()}")
return False
self.digi_call = str(conn.digi_call)
self._port_handler.link_connections[str(self.uid)] = self, conn.digi_call
self._port_handler.link_connections[str(self.uid)] = self, str(conn.digi_call)

self.LINK_Connection = conn
self.is_link = True
###############################
# Del Digi Conn
# self.own_port.delete_digi_conn(conn.uid)
# conn.own_port.delete_digi_conn(self.uid)


# self.cli = cli.cliMain.NoneCLI(self) # Disable CLI
# print("new_digi TX CONN ")
return True
Expand Down Expand Up @@ -647,10 +660,11 @@ def link_disco(self, reconnect=True):
self.LINK_Connection.conn_disco()
elif reconnect and self.is_link_remote and not self.is_digi:
# logger.debug('ReConn')
if hasattr(self.LINK_Connection, 'send_sys_Msg_to_gui'):
if all((hasattr(self.LINK_Connection, 'send_sys_Msg_to_gui'),
hasattr(self.LINK_Connection, 'my_call_str'))):
# TODO ?? Why to LINKCONN GUI ? CHANNEL ?
self.LINK_Connection.send_sys_Msg_to_gui(f'*** Reconnected to {self.my_call_str}')
self.send_to_link(f'\r*** Reconnected to {self.my_call_str}\r'.encode('ASCII', 'ignore'))
self.LINK_Connection.send_sys_Msg_to_gui(f'*** Reconnected to {self.LINK_Connection.my_call_str}')
self.send_to_link(f'\r*** Reconnected to {self.LINK_Connection.my_call_str}\r'.encode('ASCII', 'ignore'))
"""
if self.digi_call:
print("Link Disco ----")
Expand Down Expand Up @@ -1189,31 +1203,31 @@ def accept_connection(self):
self._port_handler.accept_new_connection(self)
if self.LINK_Connection:
self.LINK_Connection.cli.change_cli_state(5)
logger.debug(f"Conn {self.uid}: accept_digi_connection is LINK")
# if self.digi_call in self._port_cfg.parm_Digi_calls:
if POPT_CFG.get_digi_is_enabled(self.digi_call):
logger.debug(f"Conn {self.uid}: accept_digi_connection")
if self.accept_digi_connection():
logger.debug(f"Conn {self.uid}: accept_digi_connection True")
self.is_digi = True
return
"""
print(f"Accept Conn UID: {self.uid}")
print(f"Accept Conn digi_call: {self.digi_call}")
print(f"Accept Conn parm_Digi_calls: {self._port_cfg.parm_Digi_calls}")
"""

self.send_to_link(
f'\r*** Connected to {self.to_call_str}\r'.encode('ASCII', 'ignore')
)

def accept_digi_connection(self):
# print(f'DIGI Conn accept.. {self.uid} ?')
logger.debug(f'DIGI Conn accept.. {self.uid} ?')
if not self.LINK_Connection:
# print(f'DIGI Conn accept: No LINK_Connection {self.uid}')
# print(f'DIGI Conn accept: No LINK_Connection {self.LINK_Connection}')
logger.debug(f'DIGI Conn accept: No LINK_Connection {self.uid}')
logger.debug(f'DIGI Conn accept: No LINK_Connection {self.LINK_Connection}')

return False
digi_uid = self.LINK_Connection.uid
digi_uid = str(self.LINK_Connection.uid)
digi_uid = reverse_uid(digi_uid)
link_conn_port = self.LINK_Connection.own_port
return link_conn_port.accept_digi_conn(digi_uid)
digi_accept: bool = link_conn_port.accept_digi_conn(digi_uid)
return digi_accept

def insert_new_connection(self):
""" Insert connection for handling """
Expand Down
87 changes: 50 additions & 37 deletions ax25/ax25Digi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, digi_conf: dict):
self._ax25_conf = digi_conf.get('ax25_conf', {})
self._digi_call = digi_conf.get('digi_call', '')
self._digi_ssid = digi_conf.get('digi_ssid', 0)
self._rx_conn_uid = self._ax25_conf.get('uid', '')
self._rx_conn_uid = str(self._ax25_conf.get('uid', ''))
self._tx_conn_uid = ''
self._rx_port = digi_conf.get('rx_port', None)
self._tx_port = None
Expand All @@ -40,18 +40,17 @@ def __init__(self, digi_conf: dict):
self._rx_port,
self._port_handler
)):
logger.warning("DIGI INIT Error !")
logger.error("DIGI INIT Error !")
self._state_0_error()
"""
print(f"_ax25_conf: {self._ax25_conf}")
print(f"_digi_call: {self._digi_call}")
print(f"_rx_port: {self._rx_port}")
print(f"_port_handler: {self._port_handler}")
"""
logger.debug(f"_ax25_conf: {self._ax25_conf}")
logger.debug(f"_digi_call: {self._digi_call}")
logger.debug(f"_rx_port: {self._rx_port}")
logger.debug(f"_port_handler: {self._port_handler}")

def _init_digi_conn(self, ax25_frame):
# print("!!!! _init_digi_conn !!!!")
logger.debug("!!!! _init_digi_conn !!!!")
logger.debug(ax25_frame.get_frame_conf())
"""
try:
self._rx_conn = AX25Conn(ax25_frame, port=self._rx_port)
Expand All @@ -61,14 +60,14 @@ def _init_digi_conn(self, ax25_frame):
self._state_0_error()
return
"""
self._rx_conn = AX25Conn(ax25_frame, port=self._rx_port)
self._rx_conn = AX25Conn(ax25_frame, port=self._rx_port) #########
self._rx_conn.cli.change_cli_state(5)
self._rx_conn.is_link_remote = False
self._rx_conn.cli_remote = False
self._rx_conn.is_digi = True
self._rx_conn.my_call_str = self._digi_call
self._rx_conn.digi_call = self._digi_call
self._rx_conn_uid = self._rx_conn.uid
self._rx_conn.my_call_str = str(self._digi_call)
self._rx_conn.digi_call = str(self._digi_call)
self._rx_conn_uid = str(self._rx_conn.uid)
self._rx_conn.set_station_cfg()
"""
try:
Expand All @@ -86,20 +85,20 @@ def _init_digi_conn(self, ax25_frame):
if self._conf_digi_auto_port:
tx_port_id = -1
else:
tx_port_id = self._rx_port.port_id
tx_port_id = int(self._rx_port.port_id)

if self._conf_digi_ssid_port:
tx_port_id = self._digi_ssid
tx_port_id = int(self._digi_ssid)

ax25_frame_conf = ax25_frame.get_frame_conf()
# print(f"DIGI INIT: axConf: {ax25_frame_conf}")
tx_conn = self._port_handler.new_outgoing_connection(
dest_call=self._ax25_conf.get('to_call_str', ''),
own_call=self._ax25_conf.get('from_call_str', ''),
via_calls=ax25_frame_conf.get('via_calls_str', []), # Auto lookup in MH if not exclusive Mode
via_calls=self._ax25_conf.get('via_calls_str', []), # Auto lookup in MH if not exclusive Mode
port_id=tx_port_id, # -1 Auto lookup in MH list
exclusive=True, # True = no lookup in MH list
is_service=True
is_service=True,
# link_conn=self._rx_conn
)
if not tx_conn[0]:
logger.error(f"Digi-Error _init_digi_conn: {tx_conn[1]}")
Expand All @@ -113,7 +112,7 @@ def _init_digi_conn(self, ax25_frame):
self._tx_conn.is_link_remote = True
self._tx_conn.cli_remote = False
self._tx_conn.is_digi = True
self._tx_conn.my_call_str = self._digi_call
self._tx_conn.my_call_str = str(self._digi_call)
# self._tx_conn.digi_call = self._digi_call
self._tx_conn.set_station_cfg()
"""
Expand All @@ -124,20 +123,24 @@ def _init_digi_conn(self, ax25_frame):
return
"""

self._tx_conn_uid = self._tx_conn.uid
self._tx_conn_uid = str(self._tx_conn.uid)
self._tx_port = self._tx_conn.own_port

# self._rx_port.add_digi_conn(self) #####################################################
logger.debug(f"LinkConn : {self._port_handler.link_connections.items()}")
logger.debug(f"LinkConn : txConns: {self._tx_port.connections}")
logger.debug(f"LinkConn : txConn UID: {self._tx_conn.uid}")
logger.debug(f"LinkConn : txConn_UID: {self._tx_conn_uid}")
logger.debug(f"LinkConn : rxConns: {self._rx_port.connections}")
logger.debug(f"LinkConn : rxConn UID: {self._rx_conn.uid}")
logger.debug(f"LinkConn : rxConn_UID: {self._rx_conn_uid}")
self._state = 2

def add_rx_conn_cron(self):
logger.debug("LinkConn : ADD Crone ")
if not self._rx_conn:
logger.debug("LinkConn : ADD Crone: no rx_conn ")
self._state_0_error()
return
return False
if self._link_connections():
if self._rx_conn_uid in self._tx_port.connections:
logger.debug("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
Expand All @@ -149,27 +152,33 @@ def add_rx_conn_cron(self):
logger.debug("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
# self._tx_port.connections[str(self._tx_conn_uid)] = self._tx_conn
self._state_0_error()
return
return False
self._rx_port.connections[str(self._rx_conn_uid)] = self._rx_conn
self._port_handler.insert_new_connection_PH(self._rx_conn, is_service=True)
self._state = 3

logger.debug(f"LinkConn Accept: {self._port_handler.link_connections.items()}")
logger.debug(f"RX-State: {self._rx_conn.get_state()}")
logger.debug(f"TX-State: {self._tx_conn.get_state()}")

return
return True
logger.debug("LinkConn : ADD Crone: Fail ")
self._state_0_error()
return False

def _link_connections(self):
print("_link_connections")
if not self._rx_conn or not self._tx_conn:
self._state_0_error()
logger.error('Digi-Conn_link Error: No tx or rx conn')
return
return False

if self._rx_conn.new_digi_connection(self._tx_conn):
logger.debug('Digi-Accept')
logger.debug('Digi-Accept tX-CONN')
return True
if self._tx_conn.new_digi_connection(self._rx_conn):
logger.debug('Digi-Accept RX-CONN')
return True
logger.debug("Digi-Not Accept")
return False

def _state_0_error(self, ax25_frame=None):
Expand All @@ -181,29 +190,30 @@ def _state_0_error(self, ax25_frame=None):
def _state_1_rx(self, ax25_frame):
if ax25_frame.ctl_byte.flag == 'SABM':
if not self._tx_conn_uid:
print("_state_1_rx: not self._tx_conn_uid")
self._init_digi_conn(ax25_frame)
else:
logger.error('Digi-SABM-RX ERROR')
self._state_0_error()
# self.crone() # # SABM TX
elif ax25_frame.ctl_byte.flag == 'DISC':
elif ax25_frame.ctl_byte.flag in ['DISC', 'DM']:
# self._abort_digi_conn(ax25_frame)
logger.debug('DIGI S! DISC RX')
if self.is_done():
# self._rx_port.add_frame_to_digiBuff(ax25_frame)
self._digi_fallback(ax25_frame)
self._rx_port.add_frame_to_digiBuff(ax25_frame)
# self._digi_fallback(ax25_frame)
else:
# print('DIGI ABORT')
self._abort_digi_conn(ax25_frame)
else:
# MAYBE Fallback to simple Digi Mode ?
logger.warning(f'DIGI Not Known Frame: {ax25_frame.ctl_byte.flag}')
self._digi_fallback(ax25_frame)
self._state_0_error()
# self._digi_fallback(ax25_frame)
# self._state_0_error()

def _state_2(self, ax25_frame=None):
if ax25_frame.ctl_byte.flag == 'SABM':
# print('DIGI INIT SABM RX')
logger.debug('DIGI INIT SABM RX - state 2')
self._last_rx = time.time()
if self._check_txConn_state():
""" IF AXIP is Faster than other Port """
Expand All @@ -214,7 +224,7 @@ def _state_2(self, ax25_frame=None):
self._rx_conn.zustand_exec.change_state(5)
self._state = 3

elif ax25_frame.ctl_byte.flag == 'DISC':
elif ax25_frame.ctl_byte.flag in ['DISC', 'DM']:
self._abort_digi_conn(ax25_frame)
logger.debug('DIGI INIT DISC RX ')

Expand Down Expand Up @@ -265,10 +275,10 @@ def _UI_digi(self, ax25_frame):
if self._conf_digi_auto_port:
tx_port_id = -1
else:
tx_port_id = self._rx_port.port_id
tx_port_id = int(self._rx_port.port_id)

if self._conf_digi_ssid_port:
tx_port_id = self._digi_ssid
tx_port_id = int(self._digi_ssid)

port = self._port_handler.get_port_by_id(tx_port_id)
if not port:
Expand All @@ -281,14 +291,14 @@ def _digi_fallback(self, ax25_frame):
print('DIGI Fallback')
logger.debug('DIGI Fallback')
# self._rx_port.add_frame_to_digiBuff(ax25_frame)
self._UI_digi(ax25_frame)
# self._UI_digi(ax25_frame)

def digi_rx_handle(self, ax25_frame):
if ax25_frame.ctl_byte.flag == 'UI':
self._UI_digi(ax25_frame)
return
state_exec = self._state_tab.get(self._state, None)
if not callable(state_exec):
if state_exec is None:
self._state_0_error()
logger.error(f"DIGI-RX ERROR: not callable(state_exec) - STATE: {self._state}")
print(f"DIGI-RX ERROR: not callable(state_exec) - STATE: {self._state}")
Expand Down Expand Up @@ -408,6 +418,9 @@ def _check_buffer_limit_TxConn(self):
def get_state(self):
return self._state

def get_tx_uid(self):
return str(self._tx_conn_uid)

def _check_txConn_state(self):
if not self._tx_conn:
logger.debug('DIGI._check_txConn_state : no txConn')
Expand Down
Loading

0 comments on commit f8b369c

Please sign in to comment.