From 113526d1bfd0c6e250f6551362b954e3b49fd443 Mon Sep 17 00:00:00 2001 From: Florent de Lamotte Date: Thu, 22 May 2025 17:19:07 +0200 Subject: [PATCH] implement change_flags on contact --- README.md | 5 ++++- pyproject.toml | 4 ++-- src/meshcore_cli/meshcore_cli.py | 24 +++++++++++++++++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 75c7109..a1786ff 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Commands are given after arguments, they can be chained and some have shortcuts. Messenging msg <name> <msg> : send message to node by name m { wait_ack : wait an ack wa } - chan <nb> <msg> : send message to channel number ch + chan <nb> <msg> : send message to channel number <nb> ch public <msg> : send message to public channel (0) dch recv : reads next msg r wait_msg : wait for a message and read it wm @@ -85,9 +85,12 @@ Commands are given after arguments, they can be chained and some have shortcuts. contacts / list : gets contact list lc share_contact <ct> : share a contact with others sc export_contact <ct> : get a contact's URI ec + import_contact <URI> : import a contactt from its URI ic remove_contact <ct> : removes a contact from this node reset_path <ct> : resets path to a contact to flood rp change_path <ct> <pth> : change the path to a contact cp + change_flags <ct> <f> : change contact flags (tel_l|tel_a|star)cf + req_telemetry <ct> : prints telemetry data as json rt Repeaters login <name> <pwd> : log into a node (rep) with given pwd l logout <name> : log out of a repeater diff --git a/pyproject.toml b/pyproject.toml index d3f41d1..a9e956d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "meshcore-cli" -version = "1.0.0.rc2" +version = "0.8.2" authors = [ { name="Florent de Lamotte", email="florent@frizoncorrea.fr" }, ] @@ -17,7 +17,7 @@ classifiers = [ ] license = "MIT" license-files = ["LICEN[CS]E*"] -dependencies = [ "meshcore >= 1.9.8.dev6", "prompt_toolkit >= 3.0.50", "requests >= 2.28.0" ] +dependencies = [ "meshcore >= 1.9.8", "prompt_toolkit >= 3.0.50", "requests >= 2.28.0" ] [project.urls] Homepage = "https://github.com/fdlamotte/meshcore-cli" diff --git a/src/meshcore_cli/meshcore_cli.py b/src/meshcore_cli/meshcore_cli.py index efe2c12..50e97c8 100644 --- a/src/meshcore_cli/meshcore_cli.py +++ b/src/meshcore_cli/meshcore_cli.py @@ -22,7 +22,7 @@ from meshcore import TCPConnection, BLEConnection, SerialConnection from meshcore import MeshCore, EventType, logger # Version -VERSION = "v1.0.0rc2" +VERSION = "v0.8.2" # default ble address is stored in a config file MCCLI_CONFIG_DIR = str(Path.home()) + "/.config/meshcore/" @@ -238,6 +238,7 @@ def make_completion_dict(contacts, to=None): "path": contact_list, "reset_path" : contact_list, "change_path" : contact_list, + "change_flags" : contact_list, "remove_contact" : contact_list, "import_contact" : {"meshcore://":None}, "login" : contact_list, @@ -296,6 +297,7 @@ def make_completion_dict(contacts, to=None): "upload_contact" : None, "reset_path" : None, "change_path" : None, + "change_flags" : None, "req_telemetry" : None, }) @@ -550,6 +552,7 @@ Line starting with \"$\" or \".\" will issue a meshcli command. # same but for commands with a parameter elif contact["type"] > 0 and (line.startswith("cmd ") or\ line.startswith("cp ") or line.startswith("change_path ") or\ + line.startswith("cf ") or line.startswith("change_flags ") or\ line.startswith("login ")) : cmds = line.split(" ", 1) args = [cmds[0], contact['adv_name'], cmds[1]] @@ -1209,6 +1212,24 @@ async def next_cmd(mc, cmds, json_output=False): print(json.dumps(res.payload, indent=4)) await mc.commands.get_contacts() + case "change_flags" | "cf": + argnum = 2 + await mc.ensure_contacts() + contact = mc.get_contact_by_name(cmds[1]) + if contact is None: + if json_output : + print(json.dumps({"error" : "contact unknown", "name" : cmds[1]})) + else: + print(f"Unknown contact {cmds[1]}") + else: + res = await mc.commands.change_contact_flags(contact, int(cmds[2])) + logger.debug(res) + if res.type == EventType.ERROR: + print(f"Error setting path: {res}") + elif json_output : + print(json.dumps(res.payload, indent=4)) + await mc.commands.get_contacts() + case "reset_path" | "rp" : argnum = 1 await mc.ensure_contacts() @@ -1546,6 +1567,7 @@ def command_help(): remove_contact : removes a contact from this node reset_path : resets path to a contact to flood rp change_path : change the path to a contact cp + change_flags : change contact flags (tel_l|tel_a|star)cf req_telemetry : prints telemetry data as json rt Repeaters login : log into a node (rep) with given pwd l