Merge pull request #130 from a-f-G-U-C/team-pos-cli-202112

add cli support for team and position (fixed)
This commit is contained in:
Jm Casler
2021-12-01 08:50:49 -08:00
committed by GitHub
2 changed files with 57 additions and 3 deletions

View File

@@ -12,7 +12,7 @@ from pubsub import pub
import pyqrcode
import pkg_resources
from . import SerialInterface, TCPInterface, BLEInterface, test, remote_hardware
from . import portnums_pb2, channel_pb2
from . import portnums_pb2, channel_pb2, mesh_pb2, radioconfig_pb2
"""We only import the tunnel code if we are on a platform that can run it"""
have_tunnel = platform.system() == 'Linux'
@@ -234,6 +234,52 @@ def onConnected(interface):
print(f"Setting device owner to {args.set_owner}")
getNode().setOwner(args.set_owner)
if args.pos_fields:
# If --pos-fields invoked with args, set position fields
closeNow = True
prefs = getNode().radioConfig.preferences
allFields = 0
try:
for field in args.pos_fields:
v_field = radioconfig_pb2.PositionFlags.Value(field)
allFields |= v_field
except ValueError:
print("ERROR: supported position fields are:")
print(radioconfig_pb2.PositionFlags.keys())
print("If no fields are specified, will read and display current value.")
else:
print(f"Setting position fields to {allFields}")
setPref(prefs, 'position_flags', ('%d' % allFields))
print("Writing modified preferences to device")
getNode().writeConfig()
elif args.pos_fields is not None:
# If --pos-fields invoked without args, read and display current value
closeNow = True
prefs = getNode().radioConfig.preferences
fieldNames = []
for bit in radioconfig_pb2.PositionFlags.values():
if (prefs.position_flags & bit):
fieldNames.append(radioconfig_pb2.PositionFlags.Name(bit))
print(' '.join(fieldNames))
if args.set_team:
closeNow = True
try:
v_team = mesh_pb2.Team.Value(args.set_team.upper())
except ValueError:
v_team = 0
print(f"ERROR: Team \'{args.set_team}\' not found.")
print("Try a team name from the list below, or CLEAR for unaffiliated:")
print(mesh_pb2.Team.keys())
else:
print(f"Setting team to {mesh_pb2.Team.Name(v_team)}")
getNode().setOwner(team=v_team)
if args.set_ham:
closeNow = True
print(
@@ -305,7 +351,6 @@ def onConnected(interface):
print("Writing modified preferences to device")
getNode().writeConfig()
if args.seturl:
closeNow = True
getNode().setURL(args.seturl)
@@ -582,6 +627,9 @@ def initParser():
parser.add_argument(
"--set-owner", help="Set device owner name", action="store")
parser.add_argument(
"--set-team", help="Set team affiliation (? for options)", action="store")
parser.add_argument(
"--set-ham", help="Set licensed HAM ID and turn off encryption", action="store")
@@ -625,6 +673,10 @@ def initParser():
parser.add_argument(
"--setlon", help="Set device longitude (allows use without GPS)")
parser.add_argument(
"--pos-fields", help="Specify position message fields (? for more info)",
nargs="*", action="store")
parser.add_argument("--debug", help="Show API library debug log messages",
action="store_true")

View File

@@ -193,7 +193,7 @@ class Node:
else:
return 0
def setOwner(self, long_name, short_name=None, is_licensed=False):
def setOwner(self, long_name=None, short_name=None, is_licensed=False, team=None):
"""Set device owner name"""
nChars = 3
minChars = 2
@@ -221,6 +221,8 @@ class Node:
short_name = short_name[:nChars]
p.set_owner.short_name = short_name
p.set_owner.is_licensed = is_licensed
if team is not None:
p.set_owner.team = team
return self._sendAdmin(p)