Compare commits

..

22 Commits
2.3.0 ... 2.3.1

Author SHA1 Message Date
Ben Meadors
0738e5ec6d Remove publish mac (for now) 2024-03-21 07:35:55 -05:00
Ben Meadors
5537778b64 2.3.1 protobufs 2024-03-20 10:27:19 -05:00
Ben Meadors
341d8e0cec Merge pull request #517 from ianmcorvidae/pylint-wrangling
Pylint wrangling
2024-03-19 17:51:14 -05:00
Ian McEwen
9b5943192d Make pylint happy with ble_interface.py 2024-03-19 13:18:15 -07:00
Ian McEwen
bf56521a53 Create Tunnel.TunnelError for specialized errors in that file 2024-03-19 13:00:06 -07:00
Ian McEwen
16a1af6a13 Create MeshInterface.MeshInterfaceError to specialize errors in that file 2024-03-19 12:58:44 -07:00
Ian McEwen
b8640666d7 Fix some outstanding pylint issues (or disable the checks) 2024-03-19 12:47:08 -07:00
Ben Meadors
0528a6fb3b Merge pull request #516 from ianmcorvidae/pkgversions-ci
use importlib.metadata and packaging.version instead of pkg_resources
2024-03-19 14:24:23 -05:00
Ian McEwen
5511871442 Add packaging to setup.py. hopefully. 2024-03-19 12:20:35 -07:00
Ian McEwen
486e13a93b Add 'packaging' to requirements.txt 2024-03-19 12:17:24 -07:00
Ian McEwen
759cafb817 use importlib.metadata and packaging.version instead of pkg_resources 2024-03-19 12:02:40 -07:00
Ben Meadors
bd788ae303 Merge pull request #508 from ianmcorvidae/set-ch-index-on-add
Set --ch-index to a newly added channel when --ch-add is set, to allow further modification
2024-03-17 07:45:29 -05:00
Ben Meadors
bb8a0d987f Merge pull request #509 from ianmcorvidae/fix-chset-options-list
Make --ch-set with invalid options print out the available options
2024-03-17 07:44:30 -05:00
Ian McEwen
92cc84e692 Make --ch-set with invalid options print out the available options as the documentation says it does 2024-03-16 11:58:38 -07:00
Ian McEwen
03abaf6059 Set --ch-index to a newly added channel when --ch-add is set, to allow further modification 2024-03-16 11:06:32 -07:00
Ben Meadors
6bed30e175 Merge pull request #505 from ianmcorvidae/unknown-nodes
Show unknown nodes in a fashion similar to the web UI. Fixes #504
2024-03-14 07:38:23 -05:00
Ian McEwen
9f2cc28fef Show unknown nodes in a fashion similar to the web UI. Fixes #504 2024-03-13 21:15:00 -07:00
Ben Meadors
fdd5b866b5 Merge pull request #503 from wnagele/ble_improvements
Make BLE connections a bit more resilient
2024-03-13 08:20:55 -05:00
Wolfgang Nagele
4ebb928400 Make BLE connections a bit more resilient 2024-03-13 14:08:32 +01:00
Jonathan Bennett
4522a8a7b0 Document automatic device search 2024-03-11 18:41:20 -05:00
Jonathan Bennett
14813e5c76 Attempt TCP connection to localhost if serial detect fails 2024-03-11 18:41:20 -05:00
Ben Meadors
c67d299984 Put bump version back 2024-03-11 12:45:32 -05:00
20 changed files with 245 additions and 157 deletions

View File

@@ -14,19 +14,19 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
# - name: Bump version - name: Bump version
# run: >- run: >-
# bin/bump_version.py bin/bump_version.py
# - name: Commit updated version.py - name: Commit updated version.py
# id: commit_updated id: commit_updated
# run: | run: |
# git config --global user.name 'github-actions' git config --global user.name 'github-actions'
# git config --global user.email 'bot@noreply.github.com' git config --global user.email 'bot@noreply.github.com'
# git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
# git add setup.py git add setup.py
# git commit -m "bump version" && git push || echo "No changes to commit" git commit -m "bump version" && git push || echo "No changes to commit"
# git log -n 1 --pretty=format:"%H" | tail -n 1 | awk '{print "::set-output name=sha::"$0}' git log -n 1 --pretty=format:"%H" | tail -n 1 | awk '{print "::set-output name=sha::"$0}'
- name: Get version - name: Get version
id: get_version id: get_version
@@ -74,51 +74,51 @@ jobs:
user: __token__ user: __token__
password: ${{ secrets.PYPI_API_TOKEN }} password: ${{ secrets.PYPI_API_TOKEN }}
build-and-publish-mac: # build-and-publish-mac:
runs-on: macos-latest # runs-on: macos-latest
needs: release_create # needs: release_create
steps: # steps:
- name: Checkout # - name: Checkout
uses: actions/checkout@v3 # uses: actions/checkout@v3
with: # with:
ref: ${{ needs.release_create.outputs.new_sha }} # ref: ${{ needs.release_create.outputs.new_sha }}
- name: Set up Python 3.9 # - name: Set up Python 3.9
uses: actions/setup-python@v2 # uses: actions/setup-python@v2
with: # with:
python-version: 3.9 # python-version: 3.9
- name: Setup code signing # - name: Setup code signing
env: # env:
MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }} # MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
MACOS_CERTIFICATE_PWD: ${{ secrets.MACOS_CERTIFICATE_PWD }} # MACOS_CERTIFICATE_PWD: ${{ secrets.MACOS_CERTIFICATE_PWD }}
MACOS_KEYCHAIN_PASSWORD: ${{ secrets.MACOS_KEYCHAIN_PASSWORD }} # MACOS_KEYCHAIN_PASSWORD: ${{ secrets.MACOS_KEYCHAIN_PASSWORD }}
run: | # run: |
echo $MACOS_CERTIFICATE | base64 --decode > certificate.p12 # echo $MACOS_CERTIFICATE | base64 --decode > certificate.p12
security create-keychain -p "$MACOS_KEYCHAIN_PASSWORD" meshtastic.keychain # security create-keychain -p "$MACOS_KEYCHAIN_PASSWORD" meshtastic.keychain
security default-keychain -s meshtastic.keychain # security default-keychain -s meshtastic.keychain
security unlock-keychain -p "$MACOS_KEYCHAIN_PASSWORD" meshtastic.keychain # security unlock-keychain -p "$MACOS_KEYCHAIN_PASSWORD" meshtastic.keychain
security import certificate.p12 -k meshtastic.keychain -P "$MACOS_CERTIFICATE_PWD" -T /usr/bin/codesign # security import certificate.p12 -k meshtastic.keychain -P "$MACOS_CERTIFICATE_PWD" -T /usr/bin/codesign
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$MACOS_KEYCHAIN_PASSWORD" meshtastic.keychain # security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$MACOS_KEYCHAIN_PASSWORD" meshtastic.keychain
- name: Build # - name: Build
env: # env:
MACOS_SIGNING_IDENTITY: ${{ secrets.MACOS_SIGNING_IDENTITY }} # MACOS_SIGNING_IDENTITY: ${{ secrets.MACOS_SIGNING_IDENTITY }}
run: | # run: |
pip install pyinstaller # pip install pyinstaller
pip install -r requirements.txt # pip install -r requirements.txt
pip install . # pip install .
pyinstaller -F -n meshtastic --collect-all meshtastic --codesign-identity "$MACOS_SIGNING_IDENTITY" meshtastic/__main__.py # pyinstaller -F -n meshtastic --collect-all meshtastic --codesign-identity "$MACOS_SIGNING_IDENTITY" meshtastic/__main__.py
- name: Add mac to release # - name: Add mac to release
uses: actions/upload-release-asset@v1 # uses: actions/upload-release-asset@v1
env: # env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: # with:
upload_url: ${{ needs.release_create.outputs.upload_url }} # upload_url: ${{ needs.release_create.outputs.upload_url }}
asset_path: dist/meshtastic # asset_path: dist/meshtastic
asset_name: meshtastic_mac # asset_name: meshtastic_mac
asset_content_type: application/zip # asset_content_type: application/zip
build-and-publish-ubuntu: build-and-publish-ubuntu:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@@ -9,7 +9,6 @@ import platform
import sys import sys
import time import time
import pkg_resources
import pyqrcode import pyqrcode
import yaml import yaml
from google.protobuf.json_format import MessageToDict from google.protobuf.json_format import MessageToDict
@@ -18,6 +17,7 @@ from pubsub import pub
import meshtastic.test import meshtastic.test
import meshtastic.util import meshtastic.util
from meshtastic import channel_pb2, config_pb2, portnums_pb2, remote_hardware from meshtastic import channel_pb2, config_pb2, portnums_pb2, remote_hardware
from meshtastic.version import get_active_version
from meshtastic.__init__ import BROADCAST_ADDR from meshtastic.__init__ import BROADCAST_ADDR
from meshtastic.ble_interface import BLEInterface from meshtastic.ble_interface import BLEInterface
from meshtastic.globals import Globals from meshtastic.globals import Globals
@@ -135,7 +135,7 @@ def splitCompoundName(comp_name):
return name return name
def setPref(config, comp_name, valStr): def setPref(config, comp_name, valStr) -> bool:
"""Set a channel or preferences value""" """Set a channel or preferences value"""
name = splitCompoundName(comp_name) name = splitCompoundName(comp_name)
@@ -597,6 +597,12 @@ def onConnected(interface):
# handle changing channels # handle changing channels
if args.ch_add: if args.ch_add:
channelIndex = our_globals.get_channel_index()
if channelIndex is not None:
# Since we set the channel index after adding a channel, don't allow --ch-index
meshtastic.util.our_exit(
"Warning: '--ch-add' and '--ch-index' are incompatible. Channel not added."
)
closeNow = True closeNow = True
if len(args.ch_add) > 10: if len(args.ch_add) > 10:
meshtastic.util.our_exit( meshtastic.util.our_exit(
@@ -620,6 +626,9 @@ def onConnected(interface):
ch.role = channel_pb2.Channel.Role.SECONDARY ch.role = channel_pb2.Channel.Role.SECONDARY
print(f"Writing modified channels to device") print(f"Writing modified channels to device")
n.writeChannel(ch.index) n.writeChannel(ch.index)
if channelIndex is None:
print(f"Setting newly-added channel's {ch.index} as '--ch-index' for further modifications")
our_globals.set_channel_index(ch.index)
if args.ch_del: if args.ch_del:
closeNow = True closeNow = True
@@ -690,9 +699,29 @@ def onConnected(interface):
# Handle the channel settings # Handle the channel settings
for pref in args.ch_set or []: for pref in args.ch_set or []:
if pref[0] == "psk": if pref[0] == "psk":
found = True
ch.settings.psk = meshtastic.util.fromPSK(pref[1]) ch.settings.psk = meshtastic.util.fromPSK(pref[1])
else: else:
setPref(ch.settings, pref[0], pref[1]) found = setPref(ch.settings, pref[0], pref[1])
if not found:
category_settings = ['module_settings']
print(
f"{ch.settings.__class__.__name__} does not have an attribute {pref[0]}."
)
print("Choices are...")
for field in ch.settings.DESCRIPTOR.fields:
if field.name not in category_settings:
print(f"{field.name}")
else:
print(f"{field.name}:")
config = ch.settings.DESCRIPTOR.fields_by_name.get(field.name)
names = []
for sub_field in config.message_type.fields:
tmp_name = f"{field.name}.{sub_field.name}"
names.append(tmp_name)
for temp_name in sorted(names):
print(f" {temp_name}")
enable = True # If we set any pref, assume the user wants to enable the channel enable = True # If we set any pref, assume the user wants to enable the channel
if enable: if enable:
@@ -984,6 +1013,16 @@ def common():
message += " After running that command, log out and re-login for it to take effect.\n" message += " After running that command, log out and re-login for it to take effect.\n"
message += f"Error was:{ex}" message += f"Error was:{ex}"
meshtastic.util.our_exit(message) meshtastic.util.our_exit(message)
if client.devPath is None:
try:
client = meshtastic.tcp_interface.TCPInterface(
"localhost", debugOut=logfile, noProto=args.noproto
)
except Exception as ex:
meshtastic.util.our_exit(
f"Error connecting to localhost:{ex}", 1
)
# We assume client is fully connected now # We assume client is fully connected now
onConnected(client) onConnected(client)
@@ -1019,7 +1058,7 @@ def initParser():
parser.add_argument( parser.add_argument(
"--port", "--port",
help="The port the Meshtastic device is connected to, i.e. /dev/ttyUSB0. If unspecified, we'll try to find it.", help="The port the Meshtastic device is connected to, i.e. /dev/ttyUSB0.",
default=None, default=None,
) )
@@ -1221,7 +1260,7 @@ def initParser():
help="Request telemetry from a node. " help="Request telemetry from a node. "
"You need pass the destination ID as argument with '--dest'. " "You need pass the destination ID as argument with '--dest'. "
"For repeaters, the nodeNum is required.", "For repeaters, the nodeNum is required.",
action="store_true", action="store_true",
) )
parser.add_argument( parser.add_argument(
@@ -1360,7 +1399,7 @@ def initParser():
parser.set_defaults(deprecated=None) parser.set_defaults(deprecated=None)
the_version = pkg_resources.get_distribution("meshtastic").version the_version = get_active_version()
parser.add_argument("--version", action="version", version=f"{the_version}") parser.add_argument("--version", action="version", version=f"{the_version}")
parser.add_argument( parser.add_argument(
@@ -1377,7 +1416,9 @@ def initParser():
def main(): def main():
"""Perform command line meshtastic operations""" """Perform command line meshtastic operations"""
our_globals = Globals.getInstance() our_globals = Globals.getInstance()
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser(
epilog="If neither --port nor --host are specified, we search for a compatible serial device, "
"and if none is found, then attempt a TCP connection to localhost.")
our_globals.set_parser(parser) our_globals.set_parser(parser)
initParser() initParser()
common() common()

View File

@@ -3,12 +3,12 @@
import logging import logging
import time import time
import struct import struct
import asyncio
from threading import Thread, Event from threading import Thread, Event
from bleak import BleakScanner, BleakClient
from meshtastic.mesh_interface import MeshInterface from meshtastic.mesh_interface import MeshInterface
from meshtastic.util import our_exit from meshtastic.util import our_exit
from bleak import BleakScanner, BleakClient
import asyncio
SERVICE_UUID = "6ba1b218-15a8-461f-9fa8-5dcae273eafd" SERVICE_UUID = "6ba1b218-15a8-461f-9fa8-5dcae273eafd"
TORADIO_UUID = "f75c76d2-129e-4dad-a1dd-7866124401e7" TORADIO_UUID = "f75c76d2-129e-4dad-a1dd-7866124401e7"
@@ -17,13 +17,14 @@ FROMNUM_UUID = "ed9da18c-a800-4f66-a670-aa7547e34453"
class BLEInterface(MeshInterface): class BLEInterface(MeshInterface):
"""MeshInterface using BLE to connect to devices"""
class BLEError(Exception): class BLEError(Exception):
"""An exception class for BLE errors"""
def __init__(self, message): def __init__(self, message):
self.message = message self.message = message
super().__init__(self.message) super().__init__(self.message)
class BLEState(): # pylint: disable=C0115
class BLEState():
THREADS = False THREADS = False
BLE = False BLE = False
MESH = False MESH = False
@@ -60,7 +61,7 @@ class BLEInterface(MeshInterface):
MeshInterface.__init__(self, debugOut = debugOut, noProto = noProto) MeshInterface.__init__(self, debugOut = debugOut, noProto = noProto)
self._startConfig() self._startConfig()
if not self.noProto: if not self.noProto:
self._waitConnected() self._waitConnected(timeout = 60.0)
self.waitForConfig() self.waitForConfig()
self.state.MESH = True self.state.MESH = True
logging.debug("Mesh init finished") logging.debug("Mesh init finished")
@@ -69,13 +70,14 @@ class BLEInterface(MeshInterface):
self.client.start_notify(FROMNUM_UUID, self.from_num_handler) self.client.start_notify(FROMNUM_UUID, self.from_num_handler)
async def from_num_handler(self, _, b): async def from_num_handler(self, _, b): # pylint: disable=C0116
from_num = struct.unpack('<I', bytes(b))[0] from_num = struct.unpack('<I', bytes(b))[0]
logging.debug(f"FROMNUM notify: {from_num}") logging.debug(f"FROMNUM notify: {from_num}")
self.should_read = True self.should_read = True
def scan(self): def scan(self):
"Scan for available BLE devices"
with BLEClient() as client: with BLEClient() as client:
return [ return [
(x[0], x[1]) for x in (client.discover( (x[0], x[1]) for x in (client.discover(
@@ -86,12 +88,15 @@ class BLEInterface(MeshInterface):
def find_device(self, address): def find_device(self, address):
"Find a device by address"
meshtastic_devices = self.scan() meshtastic_devices = self.scan()
addressed_devices = list(filter(lambda x: address == x[1].local_name or address == x[0].name, meshtastic_devices)) addressed_devices = list(filter(lambda x: address in (x[1].local_name, x[0].name), meshtastic_devices))
# If nothing is found try on the address # If nothing is found try on the address
if len(addressed_devices) == 0: if len(addressed_devices) == 0:
addressed_devices = list(filter(lambda x: BLEInterface._sanitize_address(address) == BLEInterface._sanitize_address(x[0].address), meshtastic_devices)) addressed_devices = list(filter(
lambda x: BLEInterface._sanitize_address(address) == BLEInterface._sanitize_address(x[0].address),
meshtastic_devices))
if len(addressed_devices) == 0: if len(addressed_devices) == 0:
raise BLEInterface.BLEError(f"No Meshtastic BLE peripheral with identifier or address '{address}' found. Try --ble-scan to find it.") raise BLEInterface.BLEError(f"No Meshtastic BLE peripheral with identifier or address '{address}' found. Try --ble-scan to find it.")
@@ -99,7 +104,8 @@ class BLEInterface(MeshInterface):
raise BLEInterface.BLEError(f"More than one Meshtastic BLE peripheral with identifier or address '{address}' found.") raise BLEInterface.BLEError(f"More than one Meshtastic BLE peripheral with identifier or address '{address}' found.")
return addressed_devices[0][0] return addressed_devices[0][0]
def _sanitize_address(address): def _sanitize_address(address): # pylint: disable=E0213
"Standardize BLE address by removing extraneous characters and lowercasing"
return address \ return address \
.replace("-", "") \ .replace("-", "") \
.replace("_", "") \ .replace("_", "") \
@@ -107,6 +113,7 @@ class BLEInterface(MeshInterface):
.lower() .lower()
def connect(self, address): def connect(self, address):
"Connect to a device by address"
device = self.find_device(address) device = self.find_device(address)
client = BLEClient(device.address) client = BLEClient(device.address)
client.connect() client.connect()
@@ -124,9 +131,14 @@ class BLEInterface(MeshInterface):
while self._receiveThread_started.is_set(): while self._receiveThread_started.is_set():
if self.should_read: if self.should_read:
self.should_read = False self.should_read = False
retries = 0
while True: while True:
b = bytes(self.client.read_gatt_char(FROMRADIO_UUID)) b = bytes(self.client.read_gatt_char(FROMRADIO_UUID))
if not b: if not b:
if retries < 5:
time.sleep(0.1)
retries += 1
continue
break break
logging.debug(f"FROMRADIO read: {b.hex()}") logging.debug(f"FROMRADIO read: {b.hex()}")
self._handleFromRadio(b) self._handleFromRadio(b)
@@ -151,13 +163,14 @@ class BLEInterface(MeshInterface):
if self.state.THREADS: if self.state.THREADS:
self._receiveThread_started.clear() self._receiveThread_started.clear()
self._receiveThread_stopped.wait(5) self._receiveThread_stopped.wait(5)
if self.state.BLE: if self.state.BLE:
self.client.disconnect() self.client.disconnect()
self.client.close() self.client.close()
class BLEClient(): class BLEClient():
"""Client for managing connection to a BLE device"""
def __init__(self, address = None, **kwargs): def __init__(self, address = None, **kwargs):
self._eventThread = Thread(target = self._run_event_loop) self._eventThread = Thread(target = self._run_event_loop)
self._eventThread_started = Event() self._eventThread_started = Event()
@@ -172,47 +185,46 @@ class BLEClient():
self.bleak_client = BleakClient(address, **kwargs) self.bleak_client = BleakClient(address, **kwargs)
def discover(self, **kwargs): def discover(self, **kwargs): # pylint: disable=C0116
return self.async_await(BleakScanner.discover(**kwargs)) return self.async_await(BleakScanner.discover(**kwargs))
def pair(self, **kwargs): def pair(self, **kwargs): # pylint: disable=C0116
return self.async_await(self.bleak_client.pair(**kwargs)) return self.async_await(self.bleak_client.pair(**kwargs))
def connect(self, **kwargs): def connect(self, **kwargs): # pylint: disable=C0116
return self.async_await(self.bleak_client.connect(**kwargs)) return self.async_await(self.bleak_client.connect(**kwargs))
def disconnect(self, **kwargs): def disconnect(self, **kwargs): # pylint: disable=C0116
self.async_await(self.bleak_client.disconnect(**kwargs)) self.async_await(self.bleak_client.disconnect(**kwargs))
def read_gatt_char(self, *args, **kwargs): def read_gatt_char(self, *args, **kwargs): # pylint: disable=C0116
return self.async_await(self.bleak_client.read_gatt_char(*args, **kwargs)) return self.async_await(self.bleak_client.read_gatt_char(*args, **kwargs))
def write_gatt_char(self, *args, **kwargs): def write_gatt_char(self, *args, **kwargs): # pylint: disable=C0116
self.async_await(self.bleak_client.write_gatt_char(*args, **kwargs)) self.async_await(self.bleak_client.write_gatt_char(*args, **kwargs))
def start_notify(self, *args, **kwargs): def start_notify(self, *args, **kwargs): # pylint: disable=C0116
self.async_await(self.bleak_client.start_notify(*args, **kwargs)) self.async_await(self.bleak_client.start_notify(*args, **kwargs))
def close(self): # pylint: disable=C0116
def close(self):
self.async_run(self._stop_event_loop()) self.async_run(self._stop_event_loop())
self._eventThread_stopped.wait(5) self._eventThread_stopped.wait(5)
def __enter__(self): def __enter__(self):
return self return self
def __exit__(self, type, value, traceback): def __exit__(self, _type, _value, _traceback):
self.close() self.close()
def async_await(self, coro, timeout = None): # pylint: disable=C0116
def async_await(self, coro, timeout = None):
return self.async_run(coro).result(timeout) return self.async_run(coro).result(timeout)
def async_run(self, coro): def async_run(self, coro): # pylint: disable=C0116
return asyncio.run_coroutine_threadsafe(coro, self._eventLoop) return asyncio.run_coroutine_threadsafe(coro, self._eventLoop)
def _run_event_loop(self): def _run_event_loop(self):
self._eventLoop = asyncio.new_event_loop() # I don't know if the event loop can be initialized in __init__ so silencing pylint
self._eventLoop = asyncio.new_event_loop() # pylint: disable=W0201
self._eventThread_started.set() self._eventThread_started.set()
try: try:
self._eventLoop.run_forever() self._eventLoop.run_forever()

View File

@@ -14,7 +14,7 @@ _sym_db = _symbol_database.Default()
from meshtastic import localonly_pb2 as meshtastic_dot_localonly__pb2 from meshtastic import localonly_pb2 as meshtastic_dot_localonly__pb2
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1bmeshtastic/clientonly.proto\x1a\x1ameshtastic/localonly.proto\"\xf7\x01\n\rDeviceProfile\x12\x16\n\tlong_name\x18\x01 \x01(\tH\x00\x88\x01\x01\x12\x17\n\nshort_name\x18\x02 \x01(\tH\x01\x88\x01\x01\x12\x18\n\x0b\x63hannel_url\x18\x03 \x01(\tH\x02\x88\x01\x01\x12!\n\x06\x63onfig\x18\x04 \x01(\x0b\x32\x0c.LocalConfigH\x03\x88\x01\x01\x12.\n\rmodule_config\x18\x05 \x01(\x0b\x32\x12.LocalModuleConfigH\x04\x88\x01\x01\x42\x0c\n\n_long_nameB\r\n\x0b_short_nameB\x0e\n\x0c_channel_urlB\t\n\x07_configB\x10\n\x0e_module_config\"\x0b\n\tHeartbeatBe\n\x13\x63om.geeksville.meshB\x10\x43lientOnlyProtosZ\"github.com/meshtastic/go/generated\xaa\x02\x14Meshtastic.Protobufs\xba\x02\x00\x62\x06proto3') DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1bmeshtastic/clientonly.proto\x1a\x1ameshtastic/localonly.proto\"\xf7\x01\n\rDeviceProfile\x12\x16\n\tlong_name\x18\x01 \x01(\tH\x00\x88\x01\x01\x12\x17\n\nshort_name\x18\x02 \x01(\tH\x01\x88\x01\x01\x12\x18\n\x0b\x63hannel_url\x18\x03 \x01(\tH\x02\x88\x01\x01\x12!\n\x06\x63onfig\x18\x04 \x01(\x0b\x32\x0c.LocalConfigH\x03\x88\x01\x01\x12.\n\rmodule_config\x18\x05 \x01(\x0b\x32\x12.LocalModuleConfigH\x04\x88\x01\x01\x42\x0c\n\n_long_nameB\r\n\x0b_short_nameB\x0e\n\x0c_channel_urlB\t\n\x07_configB\x10\n\x0e_module_configBe\n\x13\x63om.geeksville.meshB\x10\x43lientOnlyProtosZ\"github.com/meshtastic/go/generated\xaa\x02\x14Meshtastic.Protobufs\xba\x02\x00\x62\x06proto3')
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'meshtastic.clientonly_pb2', globals()) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'meshtastic.clientonly_pb2', globals())
@@ -24,6 +24,4 @@ if _descriptor._USE_C_DESCRIPTORS == False:
DESCRIPTOR._serialized_options = b'\n\023com.geeksville.meshB\020ClientOnlyProtosZ\"github.com/meshtastic/go/generated\252\002\024Meshtastic.Protobufs\272\002\000' DESCRIPTOR._serialized_options = b'\n\023com.geeksville.meshB\020ClientOnlyProtosZ\"github.com/meshtastic/go/generated\252\002\024Meshtastic.Protobufs\272\002\000'
_DEVICEPROFILE._serialized_start=60 _DEVICEPROFILE._serialized_start=60
_DEVICEPROFILE._serialized_end=307 _DEVICEPROFILE._serialized_end=307
_HEARTBEAT._serialized_start=309
_HEARTBEAT._serialized_end=320
# @@protoc_insertion_point(module_scope) # @@protoc_insertion_point(module_scope)

View File

@@ -18,7 +18,7 @@ from meshtastic import telemetry_pb2 as meshtastic_dot_telemetry__pb2
from meshtastic import module_config_pb2 as meshtastic_dot_module__config__pb2 from meshtastic import module_config_pb2 as meshtastic_dot_module__config__pb2
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1bmeshtastic/deviceonly.proto\x1a\x18meshtastic/channel.proto\x1a\x1ameshtastic/localonly.proto\x1a\x15meshtastic/mesh.proto\x1a\x1ameshtastic/telemetry.proto\x1a\x1emeshtastic/module_config.proto\"\xc6\x02\n\x0b\x44\x65viceState\x12\x1c\n\x07my_node\x18\x02 \x01(\x0b\x32\x0b.MyNodeInfo\x12\x14\n\x05owner\x18\x03 \x01(\x0b\x32\x05.User\x12\"\n\rreceive_queue\x18\x05 \x03(\x0b\x32\x0b.MeshPacket\x12\x0f\n\x07version\x18\x08 \x01(\r\x12$\n\x0frx_text_message\x18\x07 \x01(\x0b\x32\x0b.MeshPacket\x12\x0f\n\x07no_save\x18\t \x01(\x08\x12\x15\n\rdid_gps_reset\x18\x0b \x01(\x08\x12 \n\x0brx_waypoint\x18\x0c \x01(\x0b\x32\x0b.MeshPacket\x12\x39\n\x19node_remote_hardware_pins\x18\r \x03(\x0b\x32\x16.NodeRemoteHardwarePin\x12#\n\x0cnode_db_lite\x18\x0e \x03(\x0b\x32\r.NodeInfoLite\"\xd0\x01\n\x0cNodeInfoLite\x12\x0b\n\x03num\x18\x01 \x01(\r\x12\x13\n\x04user\x18\x02 \x01(\x0b\x32\x05.User\x12\x1f\n\x08position\x18\x03 \x01(\x0b\x32\r.PositionLite\x12\x0b\n\x03snr\x18\x04 \x01(\x02\x12\x12\n\nlast_heard\x18\x05 \x01(\x07\x12&\n\x0e\x64\x65vice_metrics\x18\x06 \x01(\x0b\x32\x0e.DeviceMetrics\x12\x0f\n\x07\x63hannel\x18\x07 \x01(\r\x12\x10\n\x08via_mqtt\x18\x08 \x01(\x08\x12\x11\n\thops_away\x18\t \x01(\r\"\x85\x01\n\x0cPositionLite\x12\x12\n\nlatitude_i\x18\x01 \x01(\x0f\x12\x13\n\x0blongitude_i\x18\x02 \x01(\x0f\x12\x10\n\x08\x61ltitude\x18\x03 \x01(\x05\x12\x0c\n\x04time\x18\x04 \x01(\x07\x12,\n\x0flocation_source\x18\x05 \x01(\x0e\x32\x13.Position.LocSource\":\n\x0b\x43hannelFile\x12\x1a\n\x08\x63hannels\x18\x01 \x03(\x0b\x32\x08.Channel\x12\x0f\n\x07version\x18\x02 \x01(\r\"\xf6\x01\n\x08OEMStore\x12\x16\n\x0eoem_icon_width\x18\x01 \x01(\r\x12\x17\n\x0foem_icon_height\x18\x02 \x01(\r\x12\x15\n\roem_icon_bits\x18\x03 \x01(\x0c\x12\x1e\n\x08oem_font\x18\x04 \x01(\x0e\x32\x0c.ScreenFonts\x12\x10\n\x08oem_text\x18\x05 \x01(\t\x12\x13\n\x0boem_aes_key\x18\x06 \x01(\x0c\x12&\n\x10oem_local_config\x18\x07 \x01(\x0b\x32\x0c.LocalConfig\x12\x33\n\x17oem_local_module_config\x18\x08 \x01(\x0b\x32\x12.LocalModuleConfig\"J\n\x15NodeRemoteHardwarePin\x12\x10\n\x08node_num\x18\x01 \x01(\r\x12\x1f\n\x03pin\x18\x02 \x01(\x0b\x32\x12.RemoteHardwarePin*>\n\x0bScreenFonts\x12\x0e\n\nFONT_SMALL\x10\x00\x12\x0f\n\x0b\x46ONT_MEDIUM\x10\x01\x12\x0e\n\nFONT_LARGE\x10\x02\x42_\n\x13\x63om.geeksville.meshB\nDeviceOnlyZ\"github.com/meshtastic/go/generated\xaa\x02\x14Meshtastic.Protobufs\xba\x02\x00\x62\x06proto3') DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1bmeshtastic/deviceonly.proto\x1a\x18meshtastic/channel.proto\x1a\x1ameshtastic/localonly.proto\x1a\x15meshtastic/mesh.proto\x1a\x1ameshtastic/telemetry.proto\x1a\x1emeshtastic/module_config.proto\"\xca\x02\n\x0b\x44\x65viceState\x12\x1c\n\x07my_node\x18\x02 \x01(\x0b\x32\x0b.MyNodeInfo\x12\x14\n\x05owner\x18\x03 \x01(\x0b\x32\x05.User\x12\"\n\rreceive_queue\x18\x05 \x03(\x0b\x32\x0b.MeshPacket\x12\x0f\n\x07version\x18\x08 \x01(\r\x12$\n\x0frx_text_message\x18\x07 \x01(\x0b\x32\x0b.MeshPacket\x12\x13\n\x07no_save\x18\t \x01(\x08\x42\x02\x18\x01\x12\x15\n\rdid_gps_reset\x18\x0b \x01(\x08\x12 \n\x0brx_waypoint\x18\x0c \x01(\x0b\x32\x0b.MeshPacket\x12\x39\n\x19node_remote_hardware_pins\x18\r \x03(\x0b\x32\x16.NodeRemoteHardwarePin\x12#\n\x0cnode_db_lite\x18\x0e \x03(\x0b\x32\r.NodeInfoLite\"\xd0\x01\n\x0cNodeInfoLite\x12\x0b\n\x03num\x18\x01 \x01(\r\x12\x13\n\x04user\x18\x02 \x01(\x0b\x32\x05.User\x12\x1f\n\x08position\x18\x03 \x01(\x0b\x32\r.PositionLite\x12\x0b\n\x03snr\x18\x04 \x01(\x02\x12\x12\n\nlast_heard\x18\x05 \x01(\x07\x12&\n\x0e\x64\x65vice_metrics\x18\x06 \x01(\x0b\x32\x0e.DeviceMetrics\x12\x0f\n\x07\x63hannel\x18\x07 \x01(\r\x12\x10\n\x08via_mqtt\x18\x08 \x01(\x08\x12\x11\n\thops_away\x18\t \x01(\r\"\x85\x01\n\x0cPositionLite\x12\x12\n\nlatitude_i\x18\x01 \x01(\x0f\x12\x13\n\x0blongitude_i\x18\x02 \x01(\x0f\x12\x10\n\x08\x61ltitude\x18\x03 \x01(\x05\x12\x0c\n\x04time\x18\x04 \x01(\x07\x12,\n\x0flocation_source\x18\x05 \x01(\x0e\x32\x13.Position.LocSource\":\n\x0b\x43hannelFile\x12\x1a\n\x08\x63hannels\x18\x01 \x03(\x0b\x32\x08.Channel\x12\x0f\n\x07version\x18\x02 \x01(\r\"\xf6\x01\n\x08OEMStore\x12\x16\n\x0eoem_icon_width\x18\x01 \x01(\r\x12\x17\n\x0foem_icon_height\x18\x02 \x01(\r\x12\x15\n\roem_icon_bits\x18\x03 \x01(\x0c\x12\x1e\n\x08oem_font\x18\x04 \x01(\x0e\x32\x0c.ScreenFonts\x12\x10\n\x08oem_text\x18\x05 \x01(\t\x12\x13\n\x0boem_aes_key\x18\x06 \x01(\x0c\x12&\n\x10oem_local_config\x18\x07 \x01(\x0b\x32\x0c.LocalConfig\x12\x33\n\x17oem_local_module_config\x18\x08 \x01(\x0b\x32\x12.LocalModuleConfig\"J\n\x15NodeRemoteHardwarePin\x12\x10\n\x08node_num\x18\x01 \x01(\r\x12\x1f\n\x03pin\x18\x02 \x01(\x0b\x32\x12.RemoteHardwarePin*>\n\x0bScreenFonts\x12\x0e\n\nFONT_SMALL\x10\x00\x12\x0f\n\x0b\x46ONT_MEDIUM\x10\x01\x12\x0e\n\nFONT_LARGE\x10\x02\x42_\n\x13\x63om.geeksville.meshB\nDeviceOnlyZ\"github.com/meshtastic/go/generated\xaa\x02\x14Meshtastic.Protobufs\xba\x02\x00\x62\x06proto3')
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'meshtastic.deviceonly_pb2', globals()) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'meshtastic.deviceonly_pb2', globals())
@@ -26,18 +26,20 @@ if _descriptor._USE_C_DESCRIPTORS == False:
DESCRIPTOR._options = None DESCRIPTOR._options = None
DESCRIPTOR._serialized_options = b'\n\023com.geeksville.meshB\nDeviceOnlyZ\"github.com/meshtastic/go/generated\252\002\024Meshtastic.Protobufs\272\002\000' DESCRIPTOR._serialized_options = b'\n\023com.geeksville.meshB\nDeviceOnlyZ\"github.com/meshtastic/go/generated\252\002\024Meshtastic.Protobufs\272\002\000'
_SCREENFONTS._serialized_start=1229 _DEVICESTATE.fields_by_name['no_save']._options = None
_SCREENFONTS._serialized_end=1291 _DEVICESTATE.fields_by_name['no_save']._serialized_options = b'\030\001'
_SCREENFONTS._serialized_start=1233
_SCREENFONTS._serialized_end=1295
_DEVICESTATE._serialized_start=169 _DEVICESTATE._serialized_start=169
_DEVICESTATE._serialized_end=495 _DEVICESTATE._serialized_end=499
_NODEINFOLITE._serialized_start=498 _NODEINFOLITE._serialized_start=502
_NODEINFOLITE._serialized_end=706 _NODEINFOLITE._serialized_end=710
_POSITIONLITE._serialized_start=709 _POSITIONLITE._serialized_start=713
_POSITIONLITE._serialized_end=842 _POSITIONLITE._serialized_end=846
_CHANNELFILE._serialized_start=844 _CHANNELFILE._serialized_start=848
_CHANNELFILE._serialized_end=902 _CHANNELFILE._serialized_end=906
_OEMSTORE._serialized_start=905 _OEMSTORE._serialized_start=909
_OEMSTORE._serialized_end=1151 _OEMSTORE._serialized_end=1155
_NODEREMOTEHARDWAREPIN._serialized_start=1153 _NODEREMOTEHARDWAREPIN._serialized_start=1157
_NODEREMOTEHARDWAREPIN._serialized_end=1227 _NODEREMOTEHARDWAREPIN._serialized_end=1231
# @@protoc_insertion_point(module_scope) # @@protoc_insertion_point(module_scope)

View File

@@ -24,7 +24,7 @@ class Globals:
def __init__(self): def __init__(self):
"""Constructor for the Globals CLass""" """Constructor for the Globals CLass"""
if Globals.__instance is not None: if Globals.__instance is not None:
raise Exception("This class is a singleton") raise Exception("This class is a singleton") # pylint: disable=W0719
else: else:
Globals.__instance = self Globals.__instance = self
self.args = None self.args = None

View File

@@ -23,7 +23,6 @@ from meshtastic.__init__ import (
BROADCAST_ADDR, BROADCAST_ADDR,
BROADCAST_NUM, BROADCAST_NUM,
LOCAL_ADDR, LOCAL_ADDR,
OUR_APP_VERSION,
ResponseHandler, ResponseHandler,
protocols, protocols,
publishingThread, publishingThread,
@@ -48,6 +47,12 @@ class MeshInterface:
debugOut debugOut
""" """
class MeshInterfaceError(Exception):
"""An exception class for general mesh interface errors"""
def __init__(self, message):
self.message = message
super().__init__(self.message)
def __init__(self, debugOut=None, noProto=False): def __init__(self, debugOut=None, noProto=False):
"""Constructor """Constructor
@@ -152,13 +157,13 @@ class MeshInterface:
) )
rows = [] rows = []
if self.nodes: if self.nodesByNum:
logging.debug(f"self.nodes:{self.nodes}") logging.debug(f"self.nodes:{self.nodes}")
for node in self.nodes.values(): for node in self.nodesByNum.values():
if not includeSelf and node["num"] == self.localNode.nodeNum: if not includeSelf and node["num"] == self.localNode.nodeNum:
continue continue
row = {"N": 0} row = {"N": 0, "User": f"UNK: {node['num']}", "ID": f"!{node['num']:x}"}
user = node.get("user") user = node.get("user")
if user: if user:
@@ -314,7 +319,7 @@ class MeshInterface:
f"mesh_pb2.Constants.DATA_PAYLOAD_LEN: {mesh_pb2.Constants.DATA_PAYLOAD_LEN}" f"mesh_pb2.Constants.DATA_PAYLOAD_LEN: {mesh_pb2.Constants.DATA_PAYLOAD_LEN}"
) )
if len(data) > mesh_pb2.Constants.DATA_PAYLOAD_LEN: if len(data) > mesh_pb2.Constants.DATA_PAYLOAD_LEN:
raise Exception("Data payload too big") raise MeshInterface.MeshInterfaceError("Data payload too big")
if ( if (
portNum == portnums_pb2.PortNum.UNKNOWN_APP portNum == portnums_pb2.PortNum.UNKNOWN_APP
@@ -440,7 +445,7 @@ class MeshInterface:
destinationId = int(destinationId[1:], 16) destinationId = int(destinationId[1:], 16)
else: else:
destinationId = int(destinationId) destinationId = int(destinationId)
self.sendData( self.sendData(
r, r,
destinationId=destinationId, destinationId=destinationId,
@@ -469,7 +474,7 @@ class MeshInterface:
) )
if telemetry.device_metrics.air_util_tx is not None: if telemetry.device_metrics.air_util_tx is not None:
print(f"Transmit air utilization: {telemetry.device_metrics.air_util_tx:.2f}%") print(f"Transmit air utilization: {telemetry.device_metrics.air_util_tx:.2f}%")
elif p["decoded"]["portnum"] == 'ROUTING_APP': elif p["decoded"]["portnum"] == 'ROUTING_APP':
if p["decoded"]["routing"]["errorReason"] == 'NO_RESPONSE': if p["decoded"]["routing"]["errorReason"] == 'NO_RESPONSE':
our_exit("No response from node. At least firmware 2.1.22 is required on the destination node.") our_exit("No response from node. At least firmware 2.1.22 is required on the destination node.")
@@ -543,25 +548,25 @@ class MeshInterface:
and self.localNode.waitForConfig() and self.localNode.waitForConfig()
) )
if not success: if not success:
raise Exception("Timed out waiting for interface config") raise MeshInterface.MeshInterfaceError("Timed out waiting for interface config")
def waitForAckNak(self): def waitForAckNak(self):
"""Wait for the ack/nak""" """Wait for the ack/nak"""
success = self._timeout.waitForAckNak(self._acknowledgment) success = self._timeout.waitForAckNak(self._acknowledgment)
if not success: if not success:
raise Exception("Timed out waiting for an acknowledgment") raise MeshInterface.MeshInterfaceError("Timed out waiting for an acknowledgment")
def waitForTraceRoute(self, waitFactor): def waitForTraceRoute(self, waitFactor):
"""Wait for trace route""" """Wait for trace route"""
success = self._timeout.waitForTraceRoute(waitFactor, self._acknowledgment) success = self._timeout.waitForTraceRoute(waitFactor, self._acknowledgment)
if not success: if not success:
raise Exception("Timed out waiting for traceroute") raise MeshInterface.MeshInterfaceError("Timed out waiting for traceroute")
def waitForTelemetry(self): def waitForTelemetry(self):
"""Wait for telemetry""" """Wait for telemetry"""
success = self._timeout.waitForTelemetry(self._acknowledgment) success = self._timeout.waitForTelemetry(self._acknowledgment)
if not success: if not success:
raise Exception("Timed out waiting for telemetry") raise MeshInterface.MeshInterfaceError("Timed out waiting for telemetry")
def getMyNodeInfo(self): def getMyNodeInfo(self):
"""Get info about my node.""" """Get info about my node."""
@@ -596,7 +601,7 @@ class MeshInterface:
and raise an exception""" and raise an exception"""
if not self.noProto: if not self.noProto:
if not self.isConnected.wait(timeout): # timeout after x seconds if not self.isConnected.wait(timeout): # timeout after x seconds
raise Exception("Timed out waiting for connection completion") raise MeshInterface.MeshInterfaceError("Timed out waiting for connection completion")
# If we failed while connecting, raise the connection to the client # If we failed while connecting, raise the connection to the client
if self.failure: if self.failure:
@@ -605,7 +610,7 @@ class MeshInterface:
def _generatePacketId(self): def _generatePacketId(self):
"""Get a new unique packet ID""" """Get a new unique packet ID"""
if self.currentPacketId is None: if self.currentPacketId is None:
raise Exception("Not connected yet, can not generate packet") raise MeshInterface.MeshInterfaceError("Not connected yet, can not generate packet")
else: else:
self.currentPacketId = (self.currentPacketId + 1) & 0xFFFFFFFF self.currentPacketId = (self.currentPacketId + 1) & 0xFFFFFFFF
return self.currentPacketId return self.currentPacketId
@@ -774,7 +779,7 @@ class MeshInterface:
failmsg = None failmsg = None
if failmsg: if failmsg:
self.failure = Exception(failmsg) self.failure = MeshInterface.MeshInterfaceError(failmsg)
self.isConnected.set() # let waitConnected return this exception self.isConnected.set() # let waitConnected return this exception
self.close() self.close()
@@ -920,7 +925,7 @@ class MeshInterface:
def _getOrCreateByNum(self, nodeNum): def _getOrCreateByNum(self, nodeNum):
"""Given a nodenum find the NodeInfo in the DB (or create if necessary)""" """Given a nodenum find the NodeInfo in the DB (or create if necessary)"""
if nodeNum == BROADCAST_NUM: if nodeNum == BROADCAST_NUM:
raise Exception("Can not create/find nodenum by the broadcast num") raise MeshInterface.MeshInterfaceError("Can not create/find nodenum by the broadcast num")
if nodeNum in self.nodesByNum: if nodeNum in self.nodesByNum:
return self.nodesByNum[nodeNum] return self.nodesByNum[nodeNum]

View File

File diff suppressed because one or more lines are too long

View File

@@ -115,6 +115,7 @@ class Node:
print(f"{str(camel_to_snake(field))}:\n{str(config_values)}") print(f"{str(camel_to_snake(field))}:\n{str(config_values)}")
def requestConfig(self, configType): def requestConfig(self, configType):
"""Request the config from the node via admin message"""
if self == self.iface.localNode: if self == self.iface.localNode:
onResponse = None onResponse = None
else: else:
@@ -688,9 +689,6 @@ class Node:
logging.debug(f"Received channel {stripnl(c)}") logging.debug(f"Received channel {stripnl(c)}")
index = c.index index = c.index
# for stress testing, we can always download all channels
fastChannelDownload = True
if index >= 8 - 1: if index >= 8 - 1:
logging.debug("Finished downloading channels") logging.debug("Finished downloading channels")
@@ -703,6 +701,7 @@ class Node:
self._requestChannel(index + 1) self._requestChannel(index + 1)
def onAckNak(self, p): def onAckNak(self, p):
"""Informative handler for ACK/NAK responses"""
if p["decoded"]["routing"]["errorReason"] != "NONE": if p["decoded"]["routing"]["errorReason"] != "NONE":
print( print(
f'Received a NAK, error reason: {p["decoded"]["routing"]["errorReason"]}' f'Received a NAK, error reason: {p["decoded"]["routing"]["errorReason"]}'

View File

@@ -32,7 +32,8 @@ class SerialInterface(StreamInterface):
ports = meshtastic.util.findPorts(True) ports = meshtastic.util.findPorts(True)
logging.debug(f"ports:{ports}") logging.debug(f"ports:{ports}")
if len(ports) == 0: if len(ports) == 0:
meshtastic.util.our_exit("Warning: No Meshtastic devices detected.") print("No Serial Meshtastic device detected, attempting TCP connection on localhost.")
return
elif len(ports) > 1: elif len(ports) > 1:
message = "Warning: Multiple serial ports were detected so one serial port must be specified with the '--port'.\n" message = "Warning: Multiple serial ports were detected so one serial port must be specified with the '--port'.\n"
message += f" Ports detected:{ports}" message += f" Ports detected:{ports}"

View File

@@ -32,7 +32,7 @@ class StreamInterface(MeshInterface):
""" """
if not hasattr(self, "stream") and not noProto: if not hasattr(self, "stream") and not noProto:
raise Exception( raise Exception( # pylint: disable=W0719
"StreamInterface is now abstract (to update existing code create SerialInterface instead)" "StreamInterface is now abstract (to update existing code create SerialInterface instead)"
) )
self._rxBuf = bytes() # empty self._rxBuf = bytes() # empty

View File

@@ -23,7 +23,7 @@ from meshtastic.__main__ import (
tunnelMain, tunnelMain,
) )
from ..channel_pb2 import Channel from ..channel_pb2 import Channel # pylint: disable=E0611
# from ..ble_interface import BLEInterface # from ..ble_interface import BLEInterface
from ..node import Node from ..node import Node
@@ -388,7 +388,7 @@ def test_main_onConnected_exception(capsys):
Globals.getInstance().set_args(sys.argv) Globals.getInstance().set_args(sys.argv)
def throw_an_exception(junk): def throw_an_exception(junk):
raise Exception("Fake exception.") raise Exception("Fake exception.") # pylint: disable=W0719
iface = MagicMock(autospec=SerialInterface) iface = MagicMock(autospec=SerialInterface)
with patch("meshtastic.serial_interface.SerialInterface", return_value=iface): with patch("meshtastic.serial_interface.SerialInterface", return_value=iface):

View File

@@ -7,7 +7,7 @@ from unittest.mock import MagicMock, patch
import pytest import pytest
# from ..admin_pb2 import AdminMessage # from ..admin_pb2 import AdminMessage
from ..channel_pb2 import Channel from ..channel_pb2 import Channel # pylint: disable=E0611
from ..node import Node from ..node import Node
from ..serial_interface import SerialInterface from ..serial_interface import SerialInterface

View File

@@ -177,7 +177,7 @@ def test_catchAndIgnore(caplog):
"""Test catchAndIgnore() does not actually throw an exception, but just logs""" """Test catchAndIgnore() does not actually throw an exception, but just logs"""
def some_closure(): def some_closure():
raise Exception("foo") raise Exception("foo") # pylint: disable=W0719
with caplog.at_level(logging.DEBUG): with caplog.at_level(logging.DEBUG):
catchAndIgnore("something", some_closure) catchAndIgnore("something", some_closure)

View File

@@ -38,6 +38,12 @@ def onTunnelReceive(packet, interface): # pylint: disable=W0613
class Tunnel: class Tunnel:
"""A TUN based IP tunnel over meshtastic""" """A TUN based IP tunnel over meshtastic"""
class TunnelError(Exception):
"""An exception class for general tunnel errors"""
def __init__(self, message):
self.message = message
super().__init__(self.message)
def __init__(self, iface, subnet="10.115", netmask="255.255.0.0"): def __init__(self, iface, subnet="10.115", netmask="255.255.0.0"):
""" """
Constructor Constructor
@@ -47,19 +53,19 @@ class Tunnel:
""" """
if not iface: if not iface:
raise Exception("Tunnel() must have a interface") raise Tunnel.TunnelError("Tunnel() must have a interface")
if not subnet: if not subnet:
raise Exception("Tunnel() must have a subnet") raise Tunnel.TunnelError("Tunnel() must have a subnet")
if not netmask: if not netmask:
raise Exception("Tunnel() must have a netmask") raise Tunnel.TunnelError("Tunnel() must have a netmask")
self.iface = iface self.iface = iface
self.subnetPrefix = subnet self.subnetPrefix = subnet
if platform.system() != "Linux": if platform.system() != "Linux":
raise Exception("Tunnel() can only be run instantiated on a Linux system") raise Tunnel.TunnelError("Tunnel() can only be run instantiated on a Linux system")
our_globals = Globals.getInstance() our_globals = Globals.getInstance()
our_globals.set_tunnelInstance(self) our_globals.set_tunnelInstance(self)

View File

@@ -12,12 +12,13 @@ import time
import traceback import traceback
from queue import Queue from queue import Queue
import pkg_resources import packaging.version as pkg_version
import requests import requests
import serial import serial
import serial.tools.list_ports import serial.tools.list_ports
from meshtastic.supported_device import supported_devices from meshtastic.supported_device import supported_devices
from meshtastic.version import get_active_version
"""Some devices such as a seger jlink we never want to accidentally open""" """Some devices such as a seger jlink we never want to accidentally open"""
blacklistVids = dict.fromkeys([0x1366]) blacklistVids = dict.fromkeys([0x1366])
@@ -108,7 +109,7 @@ def stripnl(s):
def fixme(message): def fixme(message):
"""Raise an exception for things that needs to be fixed""" """Raise an exception for things that needs to be fixed"""
raise Exception(f"FIXME: {message}") raise Exception(f"FIXME: {message}") # pylint: disable=W0719
def catchAndIgnore(reason, closure): def catchAndIgnore(reason, closure):
@@ -192,7 +193,7 @@ class Timeout:
return True return True
time.sleep(self.sleepInterval) time.sleep(self.sleepInterval)
return False return False
def waitForTelemetry(self, acknowledgment): def waitForTelemetry(self, acknowledgment):
"""Block until telemetry response is received. Returns True if telemetry response has been received.""" """Block until telemetry response is received. Returns True if telemetry response has been received."""
self.reset() self.reset()
@@ -269,7 +270,7 @@ def support_info():
print(f" Machine: {platform.uname().machine}") print(f" Machine: {platform.uname().machine}")
print(f" Encoding (stdin): {sys.stdin.encoding}") print(f" Encoding (stdin): {sys.stdin.encoding}")
print(f" Encoding (stdout): {sys.stdout.encoding}") print(f" Encoding (stdout): {sys.stdout.encoding}")
the_version = pkg_resources.get_distribution("meshtastic").version the_version = get_active_version()
pypi_version = check_if_newer_version() pypi_version = check_if_newer_version()
if pypi_version: if pypi_version:
print( print(
@@ -599,9 +600,15 @@ def check_if_newer_version():
pypi_version = data["info"]["version"] pypi_version = data["info"]["version"]
except Exception: except Exception:
pass pass
act_version = pkg_resources.get_distribution("meshtastic").version act_version = get_active_version()
if pypi_version and pkg_resources.parse_version(
pypi_version try:
) <= pkg_resources.parse_version(act_version): parsed_act_version = pkg_version.parse(act_version)
parsed_pypi_version = pkg_version.parse(pypi_version)
except pkg_version.InvalidVersion:
return pypi_version
if parsed_pypi_version <= parsed_act_version:
return None return None
return pypi_version return pypi_version

13
meshtastic/version.py Normal file
View File

@@ -0,0 +1,13 @@
"""Version lookup utilities, isolated for cleanliness"""
import sys
try:
from importlib.metadata import version
except:
import pkg_resources
def get_active_version():
"""Get the currently active version using importlib, or pkg_resources if we must"""
if "importlib.metadata" in sys.modules:
return version("meshtastic")
else:
return pkg_resources.get_distribution("meshtastic").version # pylint: disable=E0601

View File

@@ -19,3 +19,4 @@ pytap2
pdoc3 pdoc3
pypubsub pypubsub
bleak bleak
packaging

View File

@@ -44,6 +44,7 @@ setup(
"timeago>=1.0.15", "timeago>=1.0.15",
"pyyaml", "pyyaml",
"bleak>=0.21.1", "bleak>=0.21.1",
"packaging",
], ],
extras_require={"tunnel": ["pytap2>=2.0.0"]}, extras_require={"tunnel": ["pytap2>=2.0.0"]},
python_requires=">=3.7", python_requires=">=3.7",