meshcore-cli 1.6.3__tar.gz → 1.6.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {meshcore_cli-1.6.3 → meshcore_cli-1.6.5}/PKG-INFO +2 -2
- {meshcore_cli-1.6.3 → meshcore_cli-1.6.5}/flake.nix +2 -2
- {meshcore_cli-1.6.3 → meshcore_cli-1.6.5}/pyproject.toml +2 -2
- {meshcore_cli-1.6.3 → meshcore_cli-1.6.5}/src/meshcore_cli/meshcore_cli.py +519 -149
- {meshcore_cli-1.6.3 → meshcore_cli-1.6.5}/.github/funding.yml +0 -0
- {meshcore_cli-1.6.3 → meshcore_cli-1.6.5}/.gitignore +0 -0
- {meshcore_cli-1.6.3 → meshcore_cli-1.6.5}/LICENSE +0 -0
- {meshcore_cli-1.6.3 → meshcore_cli-1.6.5}/README.md +0 -0
- {meshcore_cli-1.6.3 → meshcore_cli-1.6.5}/flake.lock +0 -0
- {meshcore_cli-1.6.3 → meshcore_cli-1.6.5}/scripts/README.md +0 -0
- {meshcore_cli-1.6.3 → meshcore_cli-1.6.5}/scripts/ask_mepo_coords +0 -0
- {meshcore_cli-1.6.3 → meshcore_cli-1.6.5}/scripts/contact_markers.sh +0 -0
- {meshcore_cli-1.6.3 → meshcore_cli-1.6.5}/scripts/getpos.py +0 -0
- {meshcore_cli-1.6.3 → meshcore_cli-1.6.5}/scripts/neighbour_map.sh +0 -0
- {meshcore_cli-1.6.3 → meshcore_cli-1.6.5}/src/meshcore_cli/__init__.py +0 -0
- {meshcore_cli-1.6.3 → meshcore_cli-1.6.5}/src/meshcore_cli/__main__.py +0 -0
- {meshcore_cli-1.6.3 → meshcore_cli-1.6.5}/sxmo/sxmo_accel.sh +0 -0
- {meshcore_cli-1.6.3 → meshcore_cli-1.6.5}/sxmo/sxmo_mc.sh +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: meshcore-cli
|
|
3
|
-
Version: 1.6.
|
|
3
|
+
Version: 1.6.5
|
|
4
4
|
Summary: Command line interface to meshcore companion radios and repeaters
|
|
5
5
|
Project-URL: Homepage, https://github.com/fdlamotte/meshcore-cli
|
|
6
6
|
Project-URL: Issues, https://github.com/fdlamotte/meshcore-cli/issues
|
|
@@ -11,7 +11,7 @@ Classifier: Operating System :: OS Independent
|
|
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
|
12
12
|
Requires-Python: >=3.10
|
|
13
13
|
Requires-Dist: bleak>=0.22
|
|
14
|
-
Requires-Dist: meshcore>=2.3.
|
|
14
|
+
Requires-Dist: meshcore>=2.3.15
|
|
15
15
|
Requires-Dist: prompt-toolkit>=3.0.50
|
|
16
16
|
Requires-Dist: requests>=2.28.0
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
|
|
18
18
|
meshcore = python3Packages.buildPythonPackage rec {
|
|
19
19
|
pname = "meshcore";
|
|
20
|
-
version = "2.3.
|
|
20
|
+
version = "2.3.15";
|
|
21
21
|
pyproject = true;
|
|
22
22
|
|
|
23
23
|
src = python3Packages.fetchPypi {
|
|
24
24
|
inherit pname version;
|
|
25
|
-
sha256 = "sha256-
|
|
25
|
+
sha256 = "sha256-YIR8IdclmhOmi4kAgpYiO0N8Odauwten370gjYQ50FA=";
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
build-system = [ python3Packages.hatchling ];
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "meshcore-cli"
|
|
7
|
-
version = "1.6.
|
|
7
|
+
version = "1.6.5"
|
|
8
8
|
authors = [
|
|
9
9
|
{ name="Florent de Lamotte", email="florent@frizoncorrea.fr" },
|
|
10
10
|
]
|
|
@@ -17,7 +17,7 @@ classifiers = [
|
|
|
17
17
|
]
|
|
18
18
|
license = "MIT"
|
|
19
19
|
license-files = ["LICEN[CS]E*"]
|
|
20
|
-
dependencies = [ "meshcore >= 2.3.
|
|
20
|
+
dependencies = [ "meshcore >= 2.3.15",
|
|
21
21
|
"bleak >= 0.22",
|
|
22
22
|
"prompt_toolkit >= 3.0.50",
|
|
23
23
|
"requests >= 2.28.0" ]
|
|
@@ -14,6 +14,7 @@ import serial.tools.list_ports
|
|
|
14
14
|
from pathlib import Path
|
|
15
15
|
import traceback
|
|
16
16
|
import subprocess
|
|
17
|
+
import math
|
|
17
18
|
from prompt_toolkit.shortcuts import PromptSession
|
|
18
19
|
from prompt_toolkit.shortcuts import CompleteStyle
|
|
19
20
|
from prompt_toolkit.completion import NestedCompleter, PathCompleter
|
|
@@ -34,7 +35,7 @@ except ImportError:
|
|
|
34
35
|
from meshcore import MeshCore, EventType, logger
|
|
35
36
|
|
|
36
37
|
# Version
|
|
37
|
-
VERSION = "v1.6.
|
|
38
|
+
VERSION = "v1.6.5"
|
|
38
39
|
|
|
39
40
|
# default ble address is stored in a config file
|
|
40
41
|
MCCLI_CONFIG_DIR = os.path.expanduser("~/.config/meshcore/")
|
|
@@ -68,6 +69,7 @@ JSON = False
|
|
|
68
69
|
|
|
69
70
|
PS = None
|
|
70
71
|
CS = None
|
|
72
|
+
DS = None
|
|
71
73
|
|
|
72
74
|
# Ansi colors
|
|
73
75
|
ANSI_END = "\033[0m"
|
|
@@ -115,6 +117,7 @@ ALIASES={}
|
|
|
115
117
|
HANDLERS = { # dicts that will be indexed by numbers
|
|
116
118
|
"rxlog" : {},
|
|
117
119
|
"msgs" : {},
|
|
120
|
+
"chan_data" : {},
|
|
118
121
|
}
|
|
119
122
|
LAST_HANDLER_ID = 0
|
|
120
123
|
HANDLER_QUEUE_SIZE = 100
|
|
@@ -122,6 +125,96 @@ HANDLER_QUEUE_SIZE = 100
|
|
|
122
125
|
# is the companion supposed to have cli
|
|
123
126
|
HAS_CLI_CMD = False
|
|
124
127
|
|
|
128
|
+
# for sorting and filtering in lc could be used elsewhere
|
|
129
|
+
SORTING_CRITERIA = {
|
|
130
|
+
"a": (lambda x: x.get("last_advert", 0), False),
|
|
131
|
+
"A": (lambda x: x.get("last_advert", 0), True),
|
|
132
|
+
"n": (lambda x: x.get("adv_name", ""), False),
|
|
133
|
+
"N": (lambda x: x.get("adv_name", ""), True),
|
|
134
|
+
"t": (lambda x: x.get("type" , 0), False),
|
|
135
|
+
"T": (lambda x: x.get("type" , 0), True),
|
|
136
|
+
"m": (lambda x: x.get("lastmod" , 0), False),
|
|
137
|
+
"M": (lambda x: x.get("lastmod" , 0), True),
|
|
138
|
+
"h": (lambda x: x.get("out_path_len" , 0), False),
|
|
139
|
+
"H": (lambda x: x.get("out_path_len" , 0), True),
|
|
140
|
+
"d": (lambda x: x.get("distance" , 0), False),
|
|
141
|
+
"D": (lambda x: x.get("distance" , 0), True),
|
|
142
|
+
"f": (lambda x: bool(x.get("flags" , 0) & 1), True),
|
|
143
|
+
"F": (lambda x: bool(x.get("flags" , 0) & 1), False),
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
TYPE_MAP = {
|
|
147
|
+
"1": 1, "c": 1, # client
|
|
148
|
+
"2": 2, "r": 2, # repeater
|
|
149
|
+
"3": 3, "o": 3, # room
|
|
150
|
+
"4": 4, "s": 4, # sensor
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
LC_DISPLAY_TYPES = [1, 2, 3, 4]
|
|
154
|
+
LC_OUTPUT_FORMAT = "tkah"
|
|
155
|
+
LC_SORT_ORDER = ""
|
|
156
|
+
|
|
157
|
+
def time_ago_from_timestamp (timestamp):
|
|
158
|
+
if timestamp == 0:
|
|
159
|
+
return "0"
|
|
160
|
+
|
|
161
|
+
duration = int(time.time()) - timestamp
|
|
162
|
+
in_future=False
|
|
163
|
+
if duration < 0 :
|
|
164
|
+
in_future = True
|
|
165
|
+
duration = -duration
|
|
166
|
+
if duration > 86400: # > 1 day drift
|
|
167
|
+
return ""
|
|
168
|
+
|
|
169
|
+
if duration / 86400 >= 1 : # result in days
|
|
170
|
+
days_ago = int(duration/86400)
|
|
171
|
+
if days_ago >= 365:
|
|
172
|
+
time_ago = f"{int(days_ago/365)}y"
|
|
173
|
+
else:
|
|
174
|
+
time_ago = f"{days_ago}d"
|
|
175
|
+
elif duration / 3600 >= 1 : # result in days
|
|
176
|
+
time_ago = f"{int(duration/3600)}h"
|
|
177
|
+
elif duration / 60 >= 1 : # result in min
|
|
178
|
+
time_ago = f"{int(duration/60)}m"
|
|
179
|
+
else :
|
|
180
|
+
time_ago = f"{int(duration)}s"
|
|
181
|
+
|
|
182
|
+
if in_future :
|
|
183
|
+
time_ago = "+" + time_ago
|
|
184
|
+
|
|
185
|
+
return time_ago
|
|
186
|
+
|
|
187
|
+
def haversine_distance(coord1, coord2):
|
|
188
|
+
# Radius of the Earth in kilometers (use 3958.8 for miles)
|
|
189
|
+
R = 6371.0
|
|
190
|
+
|
|
191
|
+
lat1, lon1 = coord1
|
|
192
|
+
lat2, lon2 = coord2
|
|
193
|
+
|
|
194
|
+
# Convert latitude and longitude to radians
|
|
195
|
+
lat1_rad = math.radians(lat1)
|
|
196
|
+
lon1_rad = math.radians(lon1)
|
|
197
|
+
lat2_rad = math.radians(lat2)
|
|
198
|
+
lon2_rad = math.radians(lon2)
|
|
199
|
+
|
|
200
|
+
# Differences
|
|
201
|
+
dlat = lat2_rad - lat1_rad
|
|
202
|
+
dlon = lon2_rad - lon1_rad
|
|
203
|
+
|
|
204
|
+
# Haversine formula computation
|
|
205
|
+
a = (math.sin(dlat / 2) ** 2 +
|
|
206
|
+
math.cos(lat1_rad) * math.cos(lat2_rad) * math.sin(dlon / 2) ** 2)
|
|
207
|
+
a = min(1.0, max(0.0, a))
|
|
208
|
+
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
|
|
209
|
+
|
|
210
|
+
return R * c
|
|
211
|
+
|
|
212
|
+
def distance_between(contact1, contact2):
|
|
213
|
+
# calculate distance between two contacts (can be mc.self_info)
|
|
214
|
+
coord1 = (contact1['adv_lat'], contact1['adv_lon'])
|
|
215
|
+
coord2 = (contact2['adv_lat'], contact2['adv_lon'])
|
|
216
|
+
return haversine_distance(coord1, coord2)
|
|
217
|
+
|
|
125
218
|
def enqueue_handler_event(handler_type, payload):
|
|
126
219
|
message = json.dumps(payload) + "\n"
|
|
127
220
|
for handler in HANDLERS[handler_type].values():
|
|
@@ -236,7 +329,9 @@ async def process_event_message(mc, ev, json_output, end="\n"):
|
|
|
236
329
|
|
|
237
330
|
path_str = ""
|
|
238
331
|
|
|
239
|
-
if
|
|
332
|
+
if "sender_timestamp" in data\
|
|
333
|
+
and process_event_message.timestamp != ""\
|
|
334
|
+
and process_event_message.timestamp != "off":
|
|
240
335
|
ts = data["sender_timestamp"]
|
|
241
336
|
if process_event_message.timestamp == "on":
|
|
242
337
|
if (abs(time.time()-ts) < 86400):
|
|
@@ -254,7 +349,7 @@ async def process_event_message(mc, ev, json_output, end="\n"):
|
|
|
254
349
|
if "SNR" in data and process_event_message.print_snr:
|
|
255
350
|
path_str = path_str + f",{data['SNR']}dB"
|
|
256
351
|
|
|
257
|
-
if (data['type'] == "PRIV") :
|
|
352
|
+
if ('type' in data and data['type'] == "PRIV") :
|
|
258
353
|
ct = mc.get_contact_by_key_prefix(data['pubkey_prefix'])
|
|
259
354
|
if ct is None:
|
|
260
355
|
logger.debug(f"Unknown contact with pubkey prefix: {data['pubkey_prefix']}")
|
|
@@ -292,7 +387,7 @@ async def process_event_message(mc, ev, json_output, end="\n"):
|
|
|
292
387
|
|
|
293
388
|
output_str += disp + end
|
|
294
389
|
|
|
295
|
-
elif (data['type'] == "CHAN") :
|
|
390
|
+
elif ('type' in data and data['type'] == "CHAN") :
|
|
296
391
|
path_str = f"{ANSI_YELLOW}({path_str}){ANSI_END}"
|
|
297
392
|
if hasattr(mc, "channels"):
|
|
298
393
|
ch_name = mc.channels[data['channel_idx']]['channel_name']
|
|
@@ -311,12 +406,32 @@ async def process_event_message(mc, ev, json_output, end="\n"):
|
|
|
311
406
|
disp = escape_ansi(disp)
|
|
312
407
|
|
|
313
408
|
output_str += disp + end
|
|
409
|
+
|
|
410
|
+
elif ('type' in data and data['type'] == "DATA") :
|
|
411
|
+
if process_event_message.display_channel_data:
|
|
412
|
+
path_str = f"{ANSI_YELLOW}({path_str}){ANSI_END}"
|
|
413
|
+
if hasattr(mc, "channels"):
|
|
414
|
+
ch_name = mc.channels[data['channel_idx']]['channel_name']
|
|
415
|
+
disp = f"{ANSI_GREEN}{ch_name} {path_str}"
|
|
416
|
+
process_event_message.last_node = {"adv_name" : ch_name, "type" : 0, "chan_nb" : data['channel_idx']}
|
|
417
|
+
elif data["channel_idx"] == 0: #public
|
|
418
|
+
disp = f"{ANSI_GREEN}public {path_str}"
|
|
419
|
+
process_event_message.last_node = {"adv_name" : "public", "type" : 0, "chan_nb" : 0}
|
|
420
|
+
else :
|
|
421
|
+
disp = f"{ANSI_GREEN}ch{data['channel_idx']} {path_str}"
|
|
422
|
+
process_event_message.last_node = {"adv_name" : f"ch{data['channel_idx']}", "type" : 0, "chan_nb" : data['channel_idx']}
|
|
423
|
+
disp = disp + f"{ANSI_END} "
|
|
424
|
+
disp += json.dumps(ev.payload)
|
|
425
|
+
|
|
426
|
+
output_str += disp + end
|
|
427
|
+
|
|
314
428
|
else:
|
|
315
429
|
output_str += json.dumps(ev.payload) + end
|
|
316
430
|
return output_str
|
|
317
431
|
process_event_message.print_snr=False
|
|
318
432
|
process_event_message.color=True
|
|
319
433
|
process_event_message.last_node=None
|
|
434
|
+
process_event_message.display_channel_data=True
|
|
320
435
|
process_event_message.timestamp=""
|
|
321
436
|
|
|
322
437
|
async def handle_log_rx(event):
|
|
@@ -466,24 +581,25 @@ async def log_message(mc, msg):
|
|
|
466
581
|
if log_message.file is None:
|
|
467
582
|
return
|
|
468
583
|
|
|
469
|
-
if msg["type"]
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
584
|
+
if "type" in msg and msg["type"] != "DATA":
|
|
585
|
+
if msg["type"] == "PRIV" :
|
|
586
|
+
ct = mc.get_contact_by_key_prefix(msg['pubkey_prefix'])
|
|
587
|
+
if ct is None:
|
|
588
|
+
msg["name"] = msg["pubkey_prefix"]
|
|
589
|
+
msg["sender"] = msg["pubkey_prefix"]
|
|
590
|
+
else:
|
|
591
|
+
msg["name"] = ct["adv_name"]
|
|
592
|
+
msg["sender"] = ct["adv_name"]
|
|
593
|
+
elif msg["type"] == "CHAN" :
|
|
594
|
+
if hasattr(mc, 'channels') :
|
|
595
|
+
msg["sender"] = mc.channels[msg['channel_idx']]["channel_name"]
|
|
596
|
+
else:
|
|
597
|
+
msg["sender"] = f"channel {msg['channel_idx']}"
|
|
598
|
+
msg["name"] = msg["sender"]
|
|
599
|
+
msg["timestamp"] = int(time.time())
|
|
600
|
+
|
|
601
|
+
with open(log_message.file, "a") as logfile:
|
|
602
|
+
logfile.write(json.dumps(msg) + "\n")
|
|
487
603
|
|
|
488
604
|
log_message.file=None
|
|
489
605
|
|
|
@@ -494,7 +610,11 @@ async def handle_message(event):
|
|
|
494
610
|
json_output=handle_message.json_output), end="")
|
|
495
611
|
await log_message(handle_message.mc, event.payload.copy())
|
|
496
612
|
|
|
497
|
-
|
|
613
|
+
pld = event.payload
|
|
614
|
+
if "type" in pld and pld["type"] == "DATA":
|
|
615
|
+
enqueue_handler_event("chan_data", event.payload)
|
|
616
|
+
else:
|
|
617
|
+
enqueue_handler_event("msgs", event.payload)
|
|
498
618
|
|
|
499
619
|
handle_message.json_output=False
|
|
500
620
|
handle_message.mc=None
|
|
@@ -502,7 +622,7 @@ handle_message.display=True
|
|
|
502
622
|
|
|
503
623
|
async def subscribe_to_msgs(mc, json_output=False):
|
|
504
624
|
""" Subscribe to incoming messages """
|
|
505
|
-
global PS, CS
|
|
625
|
+
global PS, CS, DS
|
|
506
626
|
await mc.ensure_contacts()
|
|
507
627
|
handle_message.json_output = json_output
|
|
508
628
|
# Subscribe to private messages
|
|
@@ -511,6 +631,9 @@ async def subscribe_to_msgs(mc, json_output=False):
|
|
|
511
631
|
# Subscribe to channel messages
|
|
512
632
|
if CS is None :
|
|
513
633
|
CS = mc.subscribe(EventType.CHANNEL_MSG_RECV, handle_message)
|
|
634
|
+
# Subscribe to channel data
|
|
635
|
+
if DS is None :
|
|
636
|
+
DS = mc.subscribe(EventType.CHANNEL_DATA_RECV, handle_message)
|
|
514
637
|
await mc.start_auto_message_fetching()
|
|
515
638
|
|
|
516
639
|
# redefine get_completion to let user put symbols in first item
|
|
@@ -573,11 +696,12 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
|
|
|
573
696
|
completion_list = {
|
|
574
697
|
"to" : to_list,
|
|
575
698
|
"/to" : to_list,
|
|
576
|
-
"public" : None,
|
|
577
|
-
"chan" : None,
|
|
578
699
|
}
|
|
579
700
|
|
|
580
701
|
root_completion_list = {
|
|
702
|
+
"public" : None,
|
|
703
|
+
"chan" : None,
|
|
704
|
+
"chan_data" : None,
|
|
581
705
|
"ver" : None,
|
|
582
706
|
"infos" : None,
|
|
583
707
|
"advert" : None,
|
|
@@ -607,12 +731,14 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
|
|
|
607
731
|
"change_path" : contact_list,
|
|
608
732
|
"change_flags" : contact_list,
|
|
609
733
|
"remove_contact" : contact_list,
|
|
734
|
+
"add_contact" : {"key type name":None},
|
|
735
|
+
"reset_advert_time" : contact_list,
|
|
610
736
|
"import_contact" : {"meshcore://":None},
|
|
611
737
|
"reload_contacts" : None,
|
|
612
738
|
"aliases" : None,
|
|
613
739
|
"aliases_load" : None,
|
|
614
740
|
"alias" : None,
|
|
615
|
-
"handler_attach": {"rxlog":None, "msgs":None},
|
|
741
|
+
"handler_attach": {"rxlog":None, "msgs":None, "chan_data":None},
|
|
616
742
|
"handler_detach": None,
|
|
617
743
|
"handlers": None,
|
|
618
744
|
"login" : contact_list,
|
|
@@ -650,7 +776,10 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
|
|
|
650
776
|
"print_timestamp" : {"on":None, "off": None, "%Y:%M":None},
|
|
651
777
|
"json_msgs" : {"on":None, "off": None},
|
|
652
778
|
"color" : {"on":None, "off":None},
|
|
779
|
+
"lc_output_format":None,
|
|
780
|
+
"lc_sort_order":None,
|
|
653
781
|
"print_adverts" : {"on":None, "off":None},
|
|
782
|
+
"display_channel_data" : {"on":None, "off":None},
|
|
654
783
|
"json_log_rx" : {"on":None, "off":None},
|
|
655
784
|
"channel_echoes" : {"on":None, "off":None},
|
|
656
785
|
"advert_echoes" : {"on":None, "off":None},
|
|
@@ -686,6 +815,9 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
|
|
|
686
815
|
"print_timestamp":None,
|
|
687
816
|
"json_msgs":None,
|
|
688
817
|
"color":None,
|
|
818
|
+
"display_channel_data":None,
|
|
819
|
+
"lc_output_format":None,
|
|
820
|
+
"lc_sort_order":None,
|
|
689
821
|
"print_adverts":None,
|
|
690
822
|
"json_log_rx":None,
|
|
691
823
|
"channel_echoes":None,
|
|
@@ -722,6 +854,7 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
|
|
|
722
854
|
"?contact_info":None,
|
|
723
855
|
"?apply_to":None,
|
|
724
856
|
"?at":None,
|
|
857
|
+
"?lc":None,
|
|
725
858
|
"?node_discover":None,
|
|
726
859
|
"?nd":None,
|
|
727
860
|
"?pending_contacts":None,
|
|
@@ -737,6 +870,7 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
|
|
|
737
870
|
"?change_path":None,
|
|
738
871
|
"?trace":None,
|
|
739
872
|
"?alias":None,
|
|
873
|
+
"?add_contact":None
|
|
740
874
|
}
|
|
741
875
|
|
|
742
876
|
contact_completion_list = {
|
|
@@ -756,6 +890,7 @@ def make_completion_dict(contacts, pending=None, to=None, channels=None):
|
|
|
756
890
|
"reset_path" : None,
|
|
757
891
|
"change_path" : None,
|
|
758
892
|
"change_flags" : None,
|
|
893
|
+
"reset_advert_time" : None,
|
|
759
894
|
"req_telemetry" : None,
|
|
760
895
|
"req_binary" : None,
|
|
761
896
|
"forget_password" : None,
|
|
@@ -1145,84 +1280,84 @@ else:
|
|
|
1145
1280
|
|
|
1146
1281
|
|
|
1147
1282
|
async def process_redirected_line(mc, line, contact=None, scope="*", prev_contact=None, prev_scope="*", json_output=False, sink=sys.stdout, end="\n"):
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
if line.startswith(">>") : # append to-file redirection
|
|
1153
|
-
line = line[2:].strip()
|
|
1154
|
-
try:
|
|
1155
|
-
fp, mcline = split_first_token(line)
|
|
1156
|
-
fp = os.path.expanduser(fp)
|
|
1157
|
-
with open(fp, "a") as file:
|
|
1158
|
-
(new_contact, new_scope, last_ack) = await process_redirected_line(mc, mcline, contact, scope, prev_contact, prev_scope, json_output=json_output, sink=file)
|
|
1159
|
-
except ValueError:
|
|
1160
|
-
logger.error("Couldn't parse filename")
|
|
1161
|
-
except OSError as e:
|
|
1162
|
-
logger.error(f"Cannot append to file: {e}")
|
|
1283
|
+
new_contact = contact
|
|
1284
|
+
new_scope = scope
|
|
1285
|
+
last_ack = True
|
|
1163
1286
|
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1287
|
+
if line.startswith(">>") : # append to-file redirection
|
|
1288
|
+
line = line[2:].strip()
|
|
1289
|
+
try:
|
|
1290
|
+
fp, mcline = split_first_token(line)
|
|
1291
|
+
fp = os.path.expanduser(fp)
|
|
1292
|
+
with open(fp, "a") as file:
|
|
1293
|
+
(new_contact, new_scope, last_ack) = await process_redirected_line(mc, mcline, contact, scope, prev_contact, prev_scope, json_output=json_output, sink=file)
|
|
1294
|
+
except ValueError:
|
|
1295
|
+
logger.error("Couldn't parse filename")
|
|
1296
|
+
except OSError as e:
|
|
1297
|
+
logger.error(f"Cannot append to file: {e}")
|
|
1175
1298
|
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
logger.error(f"Permission denied: {pcom}")
|
|
1188
|
-
except OSError as e:
|
|
1189
|
-
logger.error(f"Cannot pipe: {e}")
|
|
1190
|
-
except BrokenPipeError:
|
|
1191
|
-
logger.error(f"Broken pipe")
|
|
1299
|
+
elif line.startswith(">") : # to-file redirection
|
|
1300
|
+
line = line[1:].strip()
|
|
1301
|
+
try:
|
|
1302
|
+
fp, mcline = split_first_token(line)
|
|
1303
|
+
fp = os.path.expanduser(fp)
|
|
1304
|
+
with open(fp, "w") as file:
|
|
1305
|
+
(new_contact, new_scope, last_ack) = await process_redirected_line(mc, mcline, contact, scope, prev_contact, prev_scope, json_output=json_output, sink=file)
|
|
1306
|
+
except ValueError:
|
|
1307
|
+
logger.error("Couldn't parse filename")
|
|
1308
|
+
except OSError as e:
|
|
1309
|
+
logger.error(f"Cannot write to file: {e}")
|
|
1192
1310
|
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1311
|
+
elif line.startswith("|") : # to process redirection
|
|
1312
|
+
line = line[1:].strip()
|
|
1313
|
+
try:
|
|
1314
|
+
pcom, mcline = split_first_token(line)
|
|
1315
|
+
with subprocess.Popen(shlex.split(pcom, posix=True), stdin=subprocess.PIPE, stdout=sink,text=True) as process:
|
|
1316
|
+
(new_contact, new_scope, last_ack) = await process_redirected_line(mc, mcline, contact, scope, prev_contact, prev_scope, json_output=json_output, sink=process.stdin)
|
|
1317
|
+
except ValueError:
|
|
1318
|
+
logger.error("Couldn't parse name")
|
|
1319
|
+
except FileNotFoundError:
|
|
1320
|
+
logger.error(f"File not found {pcom}")
|
|
1321
|
+
except PermissionError:
|
|
1322
|
+
logger.error(f"Permission denied: {pcom}")
|
|
1323
|
+
except OSError as e:
|
|
1324
|
+
logger.error(f"Cannot pipe: {e}")
|
|
1325
|
+
except BrokenPipeError:
|
|
1326
|
+
logger.error(f"Broken pipe")
|
|
1327
|
+
|
|
1328
|
+
elif line.startswith("<") : # from process redirection
|
|
1329
|
+
try:
|
|
1330
|
+
if line[1] == "|":
|
|
1331
|
+
key = ""
|
|
1332
|
+
line = line[2:].strip()
|
|
1333
|
+
else:
|
|
1334
|
+
key = line[1:].split("|", 1)[0].strip()
|
|
1335
|
+
line = line[1:].split("|", 1)[1].strip()
|
|
1336
|
+
|
|
1337
|
+
pcom, mcline = split_first_token(line)
|
|
1338
|
+
res = subprocess.run(shlex.split(pcom, posix=True), capture_output=True, text=True)
|
|
1339
|
+
replacement = res.stdout.strip()
|
|
1340
|
+
if key == "":
|
|
1341
|
+
mcline = formatter.format(mcline,replacement)
|
|
1342
|
+
else:
|
|
1343
|
+
keywords = {key: replacement}
|
|
1344
|
+
mcline = formatter.format(mcline, **keywords)
|
|
1345
|
+
(new_contact, new_scope, last_ack) = await process_redirected_line(mc, mcline, contact, scope, prev_contact, prev_scope, json_output=json_output, sink=sink)
|
|
1346
|
+
except IndexError as e:
|
|
1347
|
+
logger.error(f"Error with substitution: {e}")
|
|
1348
|
+
except ValueError:
|
|
1349
|
+
logger.error("Couldn't parse name")
|
|
1350
|
+
except FileNotFoundError:
|
|
1351
|
+
logger.error(f"File not found {pcom}")
|
|
1352
|
+
except PermissionError:
|
|
1353
|
+
logger.error(f"Permission denied: {pcom}")
|
|
1354
|
+
except OSError as e:
|
|
1355
|
+
logger.error(f"Cannot pipe: {e}")
|
|
1356
|
+
except BrokenPipeError:
|
|
1357
|
+
logger.error(f"Broken pipe")
|
|
1358
|
+
else :
|
|
1359
|
+
(new_contact, new_scope, last_ack) = await process_pipeline(mc, line, contact, scope, prev_contact, prev_scope, json_output=json_output, sink=sink)
|
|
1360
|
+
return new_contact, new_scope, last_ack
|
|
1226
1361
|
|
|
1227
1362
|
async def process_pipeline(mc, pipeline, contact=None, scope="*", prev_contact=None, prev_scope="*", json_output=False, sink=sys.stdout, end="\n"):
|
|
1228
1363
|
|
|
@@ -1607,6 +1742,7 @@ async def process_contact_chat_line(mc, contact, line, inside=False, json_output
|
|
|
1607
1742
|
line.startswith("req_acl") or line == "ra" or line.startswith("ra ") or\
|
|
1608
1743
|
line.startswith("path ") or line == "path" or\
|
|
1609
1744
|
line.startswith("advert_path") or line == "ap" or line.startswith("ap ") or\
|
|
1745
|
+
line.startswith("reset_advert_time") or\
|
|
1610
1746
|
line.startswith("logout") :
|
|
1611
1747
|
args = [line.split()[0], contact['adv_name']]
|
|
1612
1748
|
out_str = ""
|
|
@@ -1767,6 +1903,8 @@ async def process_contact_chat_line(mc, contact, line, inside=False, json_output
|
|
|
1767
1903
|
async def apply_command_to_contacts(mc, contact_filter, line, json_output=False, sink=sys.stdout, end="\n"):
|
|
1768
1904
|
upd_before = None
|
|
1769
1905
|
upd_after = None
|
|
1906
|
+
adv_before = None
|
|
1907
|
+
adv_after = None
|
|
1770
1908
|
contact_type = None
|
|
1771
1909
|
min_hops = None
|
|
1772
1910
|
max_hops = None
|
|
@@ -1797,6 +1935,24 @@ async def apply_command_to_contacts(mc, contact_filter, line, json_output=False,
|
|
|
1797
1935
|
else:
|
|
1798
1936
|
logger.error(f"Time filter can only be < or >")
|
|
1799
1937
|
return ""
|
|
1938
|
+
elif f[0] == "a": # last advert
|
|
1939
|
+
val_str = f[2:]
|
|
1940
|
+
t = time.time()
|
|
1941
|
+
if val_str[-1] == "d": # value in days
|
|
1942
|
+
t = t - float(val_str[0:-1]) * 86400
|
|
1943
|
+
elif val_str[-1] == "h": # value in hours
|
|
1944
|
+
t = t - float(val_str[0:-1]) * 3600
|
|
1945
|
+
elif val_str[-1] == "m": # value in minutes
|
|
1946
|
+
t = t - float(val_str[0:-1]) * 60
|
|
1947
|
+
else:
|
|
1948
|
+
t = int(val_str)
|
|
1949
|
+
if f[1] == "<": #before
|
|
1950
|
+
adv_before = t
|
|
1951
|
+
elif f[1] == ">":
|
|
1952
|
+
adv_after = t
|
|
1953
|
+
else:
|
|
1954
|
+
logger.error(f"Time filter can only be < or >")
|
|
1955
|
+
return ""
|
|
1800
1956
|
elif f[0] == "t": # type
|
|
1801
1957
|
if f[1] == "=":
|
|
1802
1958
|
contact_type = int(f[2:])
|
|
@@ -1831,6 +1987,8 @@ async def apply_command_to_contacts(mc, contact_filter, line, json_output=False,
|
|
|
1831
1987
|
if (contact_type is None or contact["type"] == contact_type) and\
|
|
1832
1988
|
(upd_before is None or contact["lastmod"] < upd_before) and\
|
|
1833
1989
|
(upd_after is None or contact["lastmod"] > upd_after) and\
|
|
1990
|
+
(adv_before is None or contact["last_advert"] < adv_before) and\
|
|
1991
|
+
(adv_after is None or contact["last_advert"] > adv_after) and\
|
|
1834
1992
|
(min_hops is None or contact["out_path_len"] >= min_hops) and\
|
|
1835
1993
|
(max_hops is None or contact["out_path_len"] <= max_hops) and\
|
|
1836
1994
|
(flags is None or contact["flags"] & flags == flags):
|
|
@@ -2214,6 +2372,7 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
2214
2372
|
returns (following, output_str)
|
|
2215
2373
|
"""
|
|
2216
2374
|
global ARROW_HEAD, SLASH_START, SLASH_END, INVERT_SLASH, LAST_HANDLER_ID
|
|
2375
|
+
global LC_DISPLAY_TYPES, LC_OUTPUT_FORMAT, LC_SORT_ORDER
|
|
2217
2376
|
output_str = ""
|
|
2218
2377
|
try :
|
|
2219
2378
|
argnum = 0
|
|
@@ -2327,6 +2486,10 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
2327
2486
|
case "help" :
|
|
2328
2487
|
argnum = 1
|
|
2329
2488
|
get_help_for("set")
|
|
2489
|
+
case "lc_output_format":
|
|
2490
|
+
LC_OUTPUT_FORMAT=cmds[2]
|
|
2491
|
+
case "lc_sort_order":
|
|
2492
|
+
LC_SORT_ORDER=cmds[2]
|
|
2330
2493
|
case "max_flood_attempts":
|
|
2331
2494
|
msg_ack.max_flood_attempts=int(cmds[2])
|
|
2332
2495
|
case "max_attempts":
|
|
@@ -2345,6 +2508,8 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
2345
2508
|
SLASH_END = cmds[2]
|
|
2346
2509
|
case "invert_slash":
|
|
2347
2510
|
INVERT_SLASH = cmds[2] == "on"
|
|
2511
|
+
case "display_channel_data":
|
|
2512
|
+
process_event_message.display_channel_data = (cmds[2] == "on")
|
|
2348
2513
|
case "color" :
|
|
2349
2514
|
process_event_message.color = (cmds[2] == "on")
|
|
2350
2515
|
if json_output :
|
|
@@ -2613,6 +2778,16 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
2613
2778
|
match cmds[1]:
|
|
2614
2779
|
case "help":
|
|
2615
2780
|
get_help_for("get")
|
|
2781
|
+
case "lc_output_format":
|
|
2782
|
+
if json_output :
|
|
2783
|
+
output_str += json.dumps({"lc_output_format": LC_OUTPUT_FORMAT})+end
|
|
2784
|
+
else:
|
|
2785
|
+
output_str += f"lc_output_format: {LC_OUTPUT_FORMAT}{end}"
|
|
2786
|
+
case "lc_sort_order":
|
|
2787
|
+
if json_output :
|
|
2788
|
+
output_str += json.dumps({"lc_sort_order": LC_SORT_ORDER})+end
|
|
2789
|
+
else:
|
|
2790
|
+
output_str += f"lc_sort_order: \"{LC_SORT_ORDER}\"{end}"
|
|
2616
2791
|
case "max_flood_attempts":
|
|
2617
2792
|
if json_output :
|
|
2618
2793
|
output_str += json.dumps({"max_flood_attempts" : msg_ack.max_flood_attempts})+end
|
|
@@ -2633,6 +2808,11 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
2633
2808
|
output_str += json.dumps({"json_msgs" : handle_message.json_output})+end
|
|
2634
2809
|
else:
|
|
2635
2810
|
output_str += f"{'on' if handle_message.json_output else 'off'}{end}"
|
|
2811
|
+
case "display_channel_data":
|
|
2812
|
+
if json_output :
|
|
2813
|
+
output_str += json.dumps({"display_channel_data" : process_event_message.display_channel_data})+end
|
|
2814
|
+
else:
|
|
2815
|
+
output_str += f"{'on' if process_event_message.display_channel_data else 'off'}{end}"
|
|
2636
2816
|
case "color":
|
|
2637
2817
|
if json_output :
|
|
2638
2818
|
output_str += json.dumps({"color" : process_event_message.color})+end
|
|
@@ -2999,23 +3179,44 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
2999
3179
|
argnum = 2
|
|
3000
3180
|
dest = None
|
|
3001
3181
|
|
|
3002
|
-
|
|
3182
|
+
wait_ack = False
|
|
3183
|
+
|
|
3184
|
+
args = cmds[1:]
|
|
3185
|
+
while len(args) > 0 and args[0][0] == "-":
|
|
3186
|
+
argnum += 1
|
|
3187
|
+
if len(args[0]) <= 1: # just a dash
|
|
3188
|
+
args=args[1:]
|
|
3189
|
+
continue
|
|
3190
|
+
a = args[0][1:]
|
|
3191
|
+
if a[0] == "a": # wait for an ack
|
|
3192
|
+
wait_ack = True
|
|
3193
|
+
|
|
3194
|
+
args = args[1:]
|
|
3195
|
+
|
|
3196
|
+
if len(args[0]) >= 12: # possibly an hex prefix
|
|
3003
3197
|
try:
|
|
3004
|
-
dest = bytes.fromhex(
|
|
3198
|
+
dest = bytes.fromhex(args[0])
|
|
3005
3199
|
except ValueError:
|
|
3006
3200
|
dest = None
|
|
3007
3201
|
|
|
3008
3202
|
if dest is None:
|
|
3009
|
-
dest = await get_contact_from_arg(mc,
|
|
3203
|
+
dest = await get_contact_from_arg(mc, args[0])
|
|
3010
3204
|
|
|
3011
3205
|
if dest is None:
|
|
3012
3206
|
if json_output :
|
|
3013
|
-
output_str += json.dumps({"error" : "unknown destination", "dest" :
|
|
3207
|
+
output_str += json.dumps({"error" : "unknown destination", "dest" : args[0]})+end
|
|
3014
3208
|
else:
|
|
3015
|
-
output_str += f"Unknown destination {
|
|
3209
|
+
output_str += f"Unknown destination {args[0]}{end}"
|
|
3016
3210
|
|
|
3017
|
-
|
|
3018
|
-
|
|
3211
|
+
elif wait_ack:
|
|
3212
|
+
ack = await msg_ack(mc, dest, args[1])
|
|
3213
|
+
if not ack:
|
|
3214
|
+
if json_output:
|
|
3215
|
+
output_str += json.dumps({"ack" : ack})+end
|
|
3216
|
+
else:
|
|
3217
|
+
output_str += f"No ack received{end}"
|
|
3218
|
+
else:
|
|
3219
|
+
res = await send_msg(mc, dest, args[1])
|
|
3019
3220
|
logger.debug(res)
|
|
3020
3221
|
if res.type == EventType.ERROR:
|
|
3021
3222
|
output_str += f"Error sending message: {res}{end}"
|
|
@@ -3042,6 +3243,27 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
3042
3243
|
elif json_output :
|
|
3043
3244
|
output_str += json.dumps(res.payload, indent=4)+end
|
|
3044
3245
|
|
|
3246
|
+
case "chan_data" :
|
|
3247
|
+
argnum = 3 # chan/datatype/payload (path will be an option -p...)
|
|
3248
|
+
if cmds[1].isnumeric() :
|
|
3249
|
+
nb = int(cmds[1])
|
|
3250
|
+
else:
|
|
3251
|
+
chan = await get_channel_by_name(mc, cmds[1])
|
|
3252
|
+
if chan is None:
|
|
3253
|
+
nb = None
|
|
3254
|
+
else:
|
|
3255
|
+
nb = chan['channel_idx']
|
|
3256
|
+
if nb is None:
|
|
3257
|
+
logger.error("Invalid channel")
|
|
3258
|
+
else:
|
|
3259
|
+
res = await mc.commands.send_channel_data(
|
|
3260
|
+
nb, int(cmds[2]), bytes.fromhex(cmds[3]))
|
|
3261
|
+
logger.debug(res)
|
|
3262
|
+
if res.type == EventType.ERROR:
|
|
3263
|
+
output_str += f"Error sending chan data: {res}{end}"
|
|
3264
|
+
elif json_output :
|
|
3265
|
+
output_str += json.dumps(res.payload, indent=4)+end
|
|
3266
|
+
|
|
3045
3267
|
case "public" | "dch" : # default chan
|
|
3046
3268
|
argnum = 1
|
|
3047
3269
|
res = await send_chan_msg(mc, 0, cmds[1])
|
|
@@ -3482,7 +3704,9 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
3482
3704
|
output_str += json.dumps(res, indent=4)+end
|
|
3483
3705
|
else:
|
|
3484
3706
|
width = shutil.get_terminal_size(fallback=(80, 24)).columns
|
|
3485
|
-
output_str += f"Got {res['results_count']} neighbours out of {res['neighbours_count']} from {contact['adv_name']}
|
|
3707
|
+
output_str += f"Got {res['results_count']} neighbours out of {res['neighbours_count']} from {contact['adv_name']}:"
|
|
3708
|
+
if res['results_count'] > 0:
|
|
3709
|
+
output_str += '\n'
|
|
3486
3710
|
first = True
|
|
3487
3711
|
for n in res['neighbours']:
|
|
3488
3712
|
if first :
|
|
@@ -3532,40 +3756,111 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
3532
3756
|
else :
|
|
3533
3757
|
output_str += json.dumps(res)+end
|
|
3534
3758
|
|
|
3535
|
-
case "contacts" | "list" | "lc":
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
if
|
|
3539
|
-
|
|
3540
|
-
else
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3759
|
+
case "contacts" | "list" | "lc" | "reload_contacts" | "rc" :
|
|
3760
|
+
argnum = 0
|
|
3761
|
+
|
|
3762
|
+
if cmd == "rc" or cmd == "reload_contacts" :
|
|
3763
|
+
await mc.commands.get_contacts()
|
|
3764
|
+
else:
|
|
3765
|
+
await mc.ensure_contacts(follow=True)
|
|
3766
|
+
|
|
3767
|
+
sort_order = LC_SORT_ORDER
|
|
3768
|
+
display_types = LC_DISPLAY_TYPES
|
|
3769
|
+
output_format = LC_OUTPUT_FORMAT
|
|
3770
|
+
filter_flag = 0
|
|
3771
|
+
quiet = False
|
|
3772
|
+
display_total = True
|
|
3773
|
+
|
|
3774
|
+
args = cmds[1:]
|
|
3775
|
+
while len(args) > 0 and args[0][0] == "-":
|
|
3776
|
+
argnum += 1
|
|
3777
|
+
if len(args[0]) <= 1: # just a dash
|
|
3778
|
+
args=args[1:]
|
|
3779
|
+
continue
|
|
3780
|
+
a = args[0][1:]
|
|
3781
|
+
if a[0] == "s": # sorting options
|
|
3782
|
+
sort_order = a[1:]
|
|
3783
|
+
|
|
3784
|
+
elif a[0] == "f": # output format
|
|
3785
|
+
output_format = a[1:]
|
|
3786
|
+
|
|
3787
|
+
elif a[0] == "t": # type
|
|
3788
|
+
display_types = {TYPE_MAP[t] for t in a[1:] if t in TYPE_MAP}
|
|
3789
|
+
|
|
3790
|
+
elif a[0] == "b": # flag
|
|
3791
|
+
filter_flag = int(a[1:], 0)
|
|
3792
|
+
|
|
3793
|
+
elif a[0] == "q": # quiet
|
|
3794
|
+
quiet = True
|
|
3795
|
+
|
|
3796
|
+
elif a[0] == "l": # only displays contact list (no total)
|
|
3797
|
+
display_total = False
|
|
3798
|
+
|
|
3799
|
+
args=args[1:]
|
|
3800
|
+
|
|
3801
|
+
if not quiet:
|
|
3802
|
+
res = mc.contacts
|
|
3803
|
+
ct = list(res.values())
|
|
3804
|
+
|
|
3805
|
+
if "d" in output_format.lower() or "d" in sort_order.lower():
|
|
3806
|
+
# calculate distance for each node (override previous val)
|
|
3807
|
+
for c in ct:
|
|
3808
|
+
c['distance'] = distance_between(mc.self_info, c)
|
|
3809
|
+
|
|
3810
|
+
if filter_flag > 0:
|
|
3811
|
+
ct = [x for x in ct if x.get("flags", 0) & filter_flag]
|
|
3812
|
+
|
|
3813
|
+
if display_types != []:
|
|
3814
|
+
ct = [x for x in ct if x.get("type") in display_types]
|
|
3815
|
+
|
|
3816
|
+
for s in reversed(sort_order):
|
|
3817
|
+
if s not in SORTING_CRITERIA:
|
|
3818
|
+
continue
|
|
3819
|
+
keyfunc, reverse = SORTING_CRITERIA[s]
|
|
3820
|
+
ct.sort(key=keyfunc, reverse=reverse)
|
|
3821
|
+
|
|
3822
|
+
if json_output : # json output historically prints the whole dict ...
|
|
3823
|
+
# if there were no args, print the dict else the list
|
|
3824
|
+
if argnum == 0:
|
|
3825
|
+
output_str += json.dumps(res, indent=4) + end
|
|
3546
3826
|
else:
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
path_str =
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3827
|
+
output_str += json.dumps(ct, indent=4) + end
|
|
3828
|
+
else :
|
|
3829
|
+
|
|
3830
|
+
for c in ct:
|
|
3831
|
+
if c['out_path_len'] == -1:
|
|
3832
|
+
path_str = "Flood"
|
|
3833
|
+
elif c['out_path_len'] == 0:
|
|
3834
|
+
path_str = "0 hop"
|
|
3835
|
+
else:
|
|
3836
|
+
phs = c['out_path_hash_mode'] + 1
|
|
3837
|
+
plen = c['out_path_len']
|
|
3838
|
+
path_str_in = c['out_path']
|
|
3839
|
+
path_str = path_str_in[:2*phs]
|
|
3840
|
+
for i in range(1,plen):
|
|
3841
|
+
path_str = path_str + "," + path_str_in[i*phs*2:(i+1)*2*phs]
|
|
3842
|
+
#path_str = f"{c[1]['out_path']}:{c[1]['out_path_hash_mode']}"
|
|
3843
|
+
output_str += f"{c['adv_name']:30} "
|
|
3844
|
+
output_str += f"{ANSI_START}34G"
|
|
3845
|
+
for i in output_format.lower():
|
|
3846
|
+
if i == "t":
|
|
3847
|
+
output_str += f" {CONTACT_TYPENAMES[c['type']]:4}"
|
|
3848
|
+
elif i == "k":
|
|
3849
|
+
output_str += f" {c['public_key'][:12]}"
|
|
3850
|
+
elif i == "h":
|
|
3851
|
+
output_str += f" {path_str:12}"
|
|
3852
|
+
elif i == "a":
|
|
3853
|
+
output_str += f" {time_ago_from_timestamp(c['last_advert']):>4}"
|
|
3854
|
+
elif i == "m":
|
|
3855
|
+
output_str += f" {time_ago_from_timestamp(c['lastmod']):>4}"
|
|
3856
|
+
elif i == "b":
|
|
3857
|
+
output_str += f" {c['flags']:02x}"
|
|
3858
|
+
elif i == "d":
|
|
3859
|
+
output_str += f" {c['distance']:7.2f}km"
|
|
3860
|
+
output_str += "\n"
|
|
3861
|
+
if display_total:
|
|
3862
|
+
output_str += f"> {len(ct)} from {len(mc.contacts)} contacts in device{end}"
|
|
3863
|
+
# we may have an issue with display total if end is empty ...
|
|
3569
3864
|
|
|
3570
3865
|
case "pending_contacts":
|
|
3571
3866
|
if json_output:
|
|
@@ -3654,7 +3949,7 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
3654
3949
|
"public_key": cmds[1],
|
|
3655
3950
|
"type" : int (cmds[2]),
|
|
3656
3951
|
"flags" : 0,
|
|
3657
|
-
"out_path_len" :
|
|
3952
|
+
"out_path_len" : -1,
|
|
3658
3953
|
"out_path" : "",
|
|
3659
3954
|
"out_path_hash_mode" : 0,
|
|
3660
3955
|
"adv_name" : cmds[3],
|
|
@@ -3669,9 +3964,21 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
3669
3964
|
output_str += f"Error adding contact: {res}{end}"
|
|
3670
3965
|
elif json_output :
|
|
3671
3966
|
output_str += json.dumps(res.payload, indent=4)+end
|
|
3967
|
+
await mc.commands.get_contacts() # reload contacts
|
|
3672
3968
|
except ValueError:
|
|
3673
3969
|
output_str += f"Error ! Command format add_contact key type name{end}"
|
|
3674
3970
|
|
|
3971
|
+
case "reset_advert_time":
|
|
3972
|
+
argnum = 1
|
|
3973
|
+
contact = await get_contact_from_arg(mc, cmds[1])
|
|
3974
|
+
contact['last_advert'] = 0
|
|
3975
|
+
res = await mc.commands.update_contact(contact)
|
|
3976
|
+
logger.debug(res)
|
|
3977
|
+
if res.type == EventType.ERROR:
|
|
3978
|
+
output_str += f"Error while reseting last advert for: {cmds[1]}{end}"
|
|
3979
|
+
elif json_output :
|
|
3980
|
+
output_str += json.dumps(res.payload, indent=4)+end
|
|
3981
|
+
|
|
3675
3982
|
case "change_path" | "cp":
|
|
3676
3983
|
argnum = 2
|
|
3677
3984
|
contact = await get_contact_from_arg(mc, cmds[1])
|
|
@@ -4059,7 +4366,7 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
4059
4366
|
process = None
|
|
4060
4367
|
|
|
4061
4368
|
try:
|
|
4062
|
-
if not htype in ["msgs", "rxlog"]:
|
|
4369
|
+
if not htype in ["msgs", "rxlog", "chan_data"]:
|
|
4063
4370
|
raise ValueError (f"Unknown handler type {htype}")
|
|
4064
4371
|
process = await asyncio.create_subprocess_exec(
|
|
4065
4372
|
*shlex.split(cmd, posix=True),
|
|
@@ -4097,7 +4404,7 @@ async def next_cmd(mc, cmds, json_output=False, sink=sys.stdout, end="\n"):
|
|
|
4097
4404
|
case "handler_detach":
|
|
4098
4405
|
argnum = 1
|
|
4099
4406
|
nb = int(cmds[1])
|
|
4100
|
-
handlers = HANDLERS["msgs"]|HANDLERS["rxlog"]
|
|
4407
|
+
handlers = HANDLERS["msgs"]|HANDLERS["rxlog"]|HANDLERS["chan_data"]
|
|
4101
4408
|
handler = handlers[nb]
|
|
4102
4409
|
handler["closed"] = True
|
|
4103
4410
|
for task_name in ("writer_task", "output_task"):
|
|
@@ -4244,6 +4551,7 @@ def command_help():
|
|
|
4244
4551
|
export_contact <ct> : get a contact's URI ec
|
|
4245
4552
|
import_contact <URI> : import a contact from its URI ic
|
|
4246
4553
|
remove_contact <ct> : removes a contact from this node
|
|
4554
|
+
add_contact <k> <t> <n>: adds contact: key type name
|
|
4247
4555
|
path <ct> : diplays path for a contact
|
|
4248
4556
|
disc_path <ct> : discover new path and display dp
|
|
4249
4557
|
reset_path <ct> : resets path to a contact to flood rp
|
|
@@ -4294,7 +4602,9 @@ def command_usage() :
|
|
|
4294
4602
|
-P : forces pairing via the OS
|
|
4295
4603
|
-t <hostname> : connects via tcp/ip
|
|
4296
4604
|
-p <port> : specifies tcp port (default 5000)
|
|
4297
|
-
-s <port>
|
|
4605
|
+
-s <port>[:opts]: use serial port <port>
|
|
4606
|
+
opts are comma separated options
|
|
4607
|
+
rts=, dtr=, baud=
|
|
4298
4608
|
-b <baudrate> : specify baudrate
|
|
4299
4609
|
-C : toggles classic mode for prompt
|
|
4300
4610
|
-c <on/off> : disables most of color output if off
|
|
@@ -4307,6 +4617,7 @@ def get_help_for (cmdname, context="line") :
|
|
|
4307
4617
|
Filter is constructed with comma separated fields :
|
|
4308
4618
|
- u, matches modification time < or > than a timestamp
|
|
4309
4619
|
(can also be days hours or minutes ago if followed by d,h or m)
|
|
4620
|
+
- a, same as u but for advert time
|
|
4310
4621
|
- t, matches the type (1: client, 2: repeater, 3: room, 4: sensor)
|
|
4311
4622
|
- h, matches number of hops
|
|
4312
4623
|
- d, direct, similar to h>-1
|
|
@@ -4432,7 +4743,7 @@ Managing Flood Scope in interactive mode
|
|
|
4432
4743
|
- contact_type (ct)
|
|
4433
4744
|
""")
|
|
4434
4745
|
|
|
4435
|
-
elif cmdname == "pending_contacts" or cmdname == "flush_pending" or cmdname == "add_pending" or cmdname == "autoadd":
|
|
4746
|
+
elif cmdname == "pending_contacts" or cmdname == "flush_pending" or cmdname == "add_pending" or cmdname == "autoadd" or cmdname == "add_contact":
|
|
4436
4747
|
print("""Contact management
|
|
4437
4748
|
|
|
4438
4749
|
To receive a message from another user, it is necessary to have its public key. This key is stored on a contact list in the device, and this list has a finite size (50 when meshcore started, now over 350 for most devices).
|
|
@@ -4456,6 +4767,8 @@ You can also set autoadd_config flag to filter contacts that are automatically a
|
|
|
4456
4767
|
|
|
4457
4768
|
Instead of an int you can use can make a string containing keys which can be (ov, cli, rep, room or sen), parser will look for keys in the string.
|
|
4458
4769
|
|
|
4770
|
+
Contacts can also be added manually by using `add_contact` command, which takes key, type and name as parameters.
|
|
4771
|
+
|
|
4459
4772
|
Note: There is also an auto_update_contacts setting that has nothing to do with adding contacts, it permits to automatically sync contact lists between device and meshcore-cli (when there is an update in name, location or path).
|
|
4460
4773
|
""")
|
|
4461
4774
|
|
|
@@ -4569,6 +4882,37 @@ The alias command takes two parameters, alias name and value. Value can contain
|
|
|
4569
4882
|
You can list all aliases using `aliases` command and so using `.> <filename> aliases` will save the alias dict in a file (`alias` with no parameter will act as `aliases`).
|
|
4570
4883
|
|
|
4571
4884
|
To recall an alias dict from a file use `aliases_load`, with a name it will try to load aliases from a file by the given name (searching also in mccli config dir), with no name it will prompt you for a file (with a file completer).
|
|
4885
|
+
""")
|
|
4886
|
+
|
|
4887
|
+
elif cmdname=="lc" or cmdname=="contacts" or cmdname=="list" :
|
|
4888
|
+
print("""lc: displays contact list from the the node
|
|
4889
|
+
|
|
4890
|
+
lc supports four parameters:
|
|
4891
|
+
sort order : -s
|
|
4892
|
+
output format : -f
|
|
4893
|
+
filter by type: -t
|
|
4894
|
+
filter by flag: -b
|
|
4895
|
+
|
|
4896
|
+
Sort order is given as a string with different criterias (lowercase for ascending, uppercase for descending order):
|
|
4897
|
+
n: sorts by name
|
|
4898
|
+
t: sorts by type
|
|
4899
|
+
a: sorts by last advert
|
|
4900
|
+
m: sorts by modification time
|
|
4901
|
+
h: sorts by path len
|
|
4902
|
+
d: sorts by distance
|
|
4903
|
+
f: starts with favorites
|
|
4904
|
+
If several criteria are used, they are evaluated from right to left, so the leftmost one has more priority `-stfn` first sorts by name, then puts the favorites first and finally orders by type.
|
|
4905
|
+
Use get/set lc_sort_order to get or set default value
|
|
4906
|
+
|
|
4907
|
+
Output format is given as a string with one character by field. Name is always displayed first but you can tailor the rest of the output:
|
|
4908
|
+
t: type
|
|
4909
|
+
k: key prefix
|
|
4910
|
+
a: last advert
|
|
4911
|
+
m: last modification
|
|
4912
|
+
h: hop count
|
|
4913
|
+
d: distance (in km)
|
|
4914
|
+
b: flag bits (as hex)
|
|
4915
|
+
Use get/set lc_output_format to get or set default value
|
|
4572
4916
|
""")
|
|
4573
4917
|
|
|
4574
4918
|
else:
|
|
@@ -5027,6 +5371,12 @@ async def main(argv):
|
|
|
5027
5371
|
first_device = False
|
|
5028
5372
|
quiet = False
|
|
5029
5373
|
force_interactive = False
|
|
5374
|
+
serial_dtr = True
|
|
5375
|
+
serial_rts = False
|
|
5376
|
+
|
|
5377
|
+
# basic logger configuration (was removed from meshcore_py)
|
|
5378
|
+
logging.basicConfig(level=logging.INFO)
|
|
5379
|
+
|
|
5030
5380
|
# If there is an address in config file, use it by default
|
|
5031
5381
|
# unless an arg is explicitely given
|
|
5032
5382
|
if os.path.exists(MCCLI_ADDRESS) :
|
|
@@ -5057,6 +5407,26 @@ async def main(argv):
|
|
|
5057
5407
|
case "-P" : # pairing
|
|
5058
5408
|
pin = True
|
|
5059
5409
|
case "-s" : # serial port
|
|
5410
|
+
if ":" in arg:
|
|
5411
|
+
serial_opts=arg.split(":",1)[1].split(',')
|
|
5412
|
+
arg=arg.split(":")[0]
|
|
5413
|
+
for opt in serial_opts:
|
|
5414
|
+
try:
|
|
5415
|
+
name = opt.split('=')[0].lower().strip()
|
|
5416
|
+
if name == 'dtr':
|
|
5417
|
+
val = opt.split('=')[1].lower()
|
|
5418
|
+
serial_dtr = True if val == 'true' or val == '1' or val == 'on' else False
|
|
5419
|
+
elif name == 'rts':
|
|
5420
|
+
val = opt.split('=')[1].lower()
|
|
5421
|
+
serial_rts = True if val == 'true' or val == '1' or val == 'on' else False
|
|
5422
|
+
elif name == 'baudrate' or name == 'baud' or name == 'b':
|
|
5423
|
+
baudrate = int(opt.split('=')[1])
|
|
5424
|
+
else:
|
|
5425
|
+
logger.error(f"Unrecognized serial option {opt}")
|
|
5426
|
+
except ValueError as e:
|
|
5427
|
+
logger.error(f"Bad option format {opt}: {e}")
|
|
5428
|
+
except IndexError as e:
|
|
5429
|
+
logger.error(f"Bad option format {opt}: {e}")
|
|
5060
5430
|
serial_port = arg
|
|
5061
5431
|
case "-b" :
|
|
5062
5432
|
baudrate = int(arg)
|
|
@@ -5165,7 +5535,7 @@ async def main(argv):
|
|
|
5165
5535
|
if not hostname is None : # connect via tcp
|
|
5166
5536
|
mc = await MeshCore.create_tcp(host=hostname, port=port, debug=debug, only_error=json_output)
|
|
5167
5537
|
elif not serial_port is None : # connect via serial port
|
|
5168
|
-
mc = await MeshCore.create_serial(port=serial_port, baudrate=baudrate, debug=debug, only_error=json_output)
|
|
5538
|
+
mc = await MeshCore.create_serial(port=serial_port, baudrate=baudrate, debug=debug, only_error=json_output, dtr=serial_dtr, rts=serial_rts)
|
|
5169
5539
|
if mc is None: # did not connect
|
|
5170
5540
|
logger.error("To connect to a repeater, use -r option.")
|
|
5171
5541
|
elif BLEAK_AVAILABLE : # connect via ble
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|