mirror of
https://github.com/TheCommsChannel/TC2-BBS-mesh.git
synced 2025-08-07 14:12:19 -04:00
Add files via upload
This commit is contained in:
parent
36ac328636
commit
339210401f
10 changed files with 1054 additions and 0 deletions
39
config_init.py
Normal file
39
config_init.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
import configparser
|
||||
import time
|
||||
import meshtastic.serial_interface
|
||||
import meshtastic.tcp_interface
|
||||
import serial.tools.list_ports
|
||||
|
||||
def initialize_config():
|
||||
config = configparser.ConfigParser()
|
||||
config.read('config.ini')
|
||||
interface_type = config['interface']['type']
|
||||
hostname = config['interface'].get('hostname', None)
|
||||
port = config['interface'].get('port', None)
|
||||
bbs_nodes = config['sync']['bbs_nodes'].split(',')
|
||||
return config, interface_type, hostname, port, bbs_nodes
|
||||
|
||||
def get_interface(interface_type, hostname=None, port=None):
|
||||
while True:
|
||||
try:
|
||||
if interface_type == 'serial':
|
||||
if port:
|
||||
return meshtastic.serial_interface.SerialInterface(port)
|
||||
else:
|
||||
ports = list(serial.tools.list_ports.comports())
|
||||
if len(ports) == 1:
|
||||
return meshtastic.serial_interface.SerialInterface(ports[0].device)
|
||||
elif len(ports) > 1:
|
||||
port_list = ', '.join([p.device for p in ports])
|
||||
raise ValueError(f"Multiple serial ports detected: {port_list}. Specify one with the 'port' argument.")
|
||||
else:
|
||||
raise ValueError("No serial ports detected.")
|
||||
elif interface_type == 'tcp':
|
||||
if not hostname:
|
||||
raise ValueError("Hostname must be specified for TCP interface")
|
||||
return meshtastic.tcp_interface.TCPInterface(hostname=hostname)
|
||||
else:
|
||||
raise ValueError("Invalid interface type specified in config file")
|
||||
except PermissionError as e:
|
||||
print(f"PermissionError: {e}. Retrying in 5 seconds...")
|
||||
time.sleep(5)
|
Loading…
Add table
Add a link
Reference in a new issue