mirror of
https://github.com/meshcore-dev/meshcore-cli.git
synced 2026-04-20 22:13:48 +00:00
wait_login and wait_status
This commit is contained in:
parent
0381a6eb2f
commit
f61ccf2b57
1 changed files with 46 additions and 33 deletions
79
mccli.py
79
mccli.py
|
|
@ -30,8 +30,8 @@ MCCLI_ADDRESS = MCCLI_CONFIG_DIR + "default_address"
|
||||||
# if None or "" then a scan is performed
|
# if None or "" then a scan is performed
|
||||||
ADDRESS = ""
|
ADDRESS = ""
|
||||||
|
|
||||||
def printerr (str) :
|
def printerr (s) :
|
||||||
sys.stderr.write(str)
|
sys.stderr.write(str(s))
|
||||||
sys.stderr.write("\n")
|
sys.stderr.write("\n")
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
|
||||||
|
|
@ -248,6 +248,7 @@ class MeshCore:
|
||||||
self.rx_sem = asyncio.Semaphore(0)
|
self.rx_sem = asyncio.Semaphore(0)
|
||||||
self.ack_ev = asyncio.Event()
|
self.ack_ev = asyncio.Event()
|
||||||
self.login_resp = asyncio.Future()
|
self.login_resp = asyncio.Future()
|
||||||
|
self.status_resp = asyncio.Future()
|
||||||
|
|
||||||
self.cx = cx
|
self.cx = cx
|
||||||
cx.set_mc(self)
|
cx.set_mc(self)
|
||||||
|
|
@ -375,7 +376,8 @@ class MeshCore:
|
||||||
res["last_snr"] = int.from_bytes(data[50:52], byteorder='little', signed=True) / 4
|
res["last_snr"] = int.from_bytes(data[50:52], byteorder='little', signed=True) / 4
|
||||||
res["direct_dups"] = int.from_bytes(data[52:54], byteorder='little')
|
res["direct_dups"] = int.from_bytes(data[52:54], byteorder='little')
|
||||||
res["flood_dups"] = int.from_bytes(data[54:56], byteorder='little')
|
res["flood_dups"] = int.from_bytes(data[54:56], byteorder='little')
|
||||||
print(res)
|
self.status_resp.set_result(res)
|
||||||
|
#printerr(res)
|
||||||
# unhandled
|
# unhandled
|
||||||
case _:
|
case _:
|
||||||
printerr (f"Unhandled data received {data}")
|
printerr (f"Unhandled data received {data}")
|
||||||
|
|
@ -478,9 +480,17 @@ class MeshCore:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
async def send_statusreq(self, dst):
|
async def send_statusreq(self, dst):
|
||||||
|
self.status_resp = asyncio.Future()
|
||||||
data = b"\x1b" + dst
|
data = b"\x1b" + dst
|
||||||
return await self.send(data)
|
return await self.send(data)
|
||||||
|
|
||||||
|
async def wait_status(self, timeout = 5):
|
||||||
|
try :
|
||||||
|
return await asyncio.wait_for(self.status_resp, timeout)
|
||||||
|
except TimeoutError :
|
||||||
|
printerr ("Timeout...")
|
||||||
|
return False
|
||||||
|
|
||||||
async def send_cmd(self, dst, cmd):
|
async def send_cmd(self, dst, cmd):
|
||||||
""" Send a cmd to a node """
|
""" Send a cmd to a node """
|
||||||
timestamp = (await self.get_time()).to_bytes(4, 'little')
|
timestamp = (await self.get_time()).to_bytes(4, 'little')
|
||||||
|
|
@ -551,10 +561,14 @@ async def next_cmd(mc, cmds):
|
||||||
await mc.ensure_contacts()
|
await mc.ensure_contacts()
|
||||||
print(await mc.send_login(bytes.fromhex(mc.contacts[cmds[1]]["public_key"]),
|
print(await mc.send_login(bytes.fromhex(mc.contacts[cmds[1]]["public_key"]),
|
||||||
cmds[2]))
|
cmds[2]))
|
||||||
|
case "wait_login":
|
||||||
|
print(await mc.wait_login())
|
||||||
case "req_status" :
|
case "req_status" :
|
||||||
argnum = 1
|
argnum = 1
|
||||||
await mc.ensure_contacts()
|
await mc.ensure_contacts()
|
||||||
print(await mc.send_statusreq(bytes.fromhex(mc.contacts[cmds[1]]["public_key"])))
|
print(await mc.send_statusreq(bytes.fromhex(mc.contacts[cmds[1]]["public_key"])))
|
||||||
|
case "wait_status" :
|
||||||
|
print(await mc.wait_status())
|
||||||
case "contacts" :
|
case "contacts" :
|
||||||
print(json.dumps(await mc.get_contacts(),indent=4))
|
print(json.dumps(await mc.get_contacts(),indent=4))
|
||||||
case "change_path":
|
case "change_path":
|
||||||
|
|
@ -588,8 +602,6 @@ async def next_cmd(mc, cmds):
|
||||||
print (res)
|
print (res)
|
||||||
case "wait_ack" :
|
case "wait_ack" :
|
||||||
await mc.wait_ack()
|
await mc.wait_ack()
|
||||||
case "wait_login":
|
|
||||||
print(await mc.wait_login())
|
|
||||||
case "infos" :
|
case "infos" :
|
||||||
print(json.dumps(mc.self_info,indent=4))
|
print(json.dumps(mc.self_info,indent=4))
|
||||||
case "advert" :
|
case "advert" :
|
||||||
|
|
@ -620,34 +632,35 @@ def usage () :
|
||||||
-b <baudrate> : specify baudrate
|
-b <baudrate> : specify baudrate
|
||||||
|
|
||||||
Available Commands (can be chained) :
|
Available Commands (can be chained) :
|
||||||
infos : print informations about the node
|
infos : print informations about the node
|
||||||
reboot
|
reboot : reboots node
|
||||||
send <key> <msg> : sends msg to the node with pubkey starting by key
|
send <key> <msg> : sends msg to the node with pubkey starting by key
|
||||||
sendto <name> <msg> : sends msg to the node with given name
|
sendto <name> <msg> : sends msg to the node with given name
|
||||||
msg <name> <msg> : same as sendto
|
msg <name> <msg> : same as sendto
|
||||||
wait_ack : wait an ack for last sent msg
|
wait_ack : wait an ack for last sent msg
|
||||||
recv : reads next msg
|
recv : reads next msg
|
||||||
sync_msgs : gets all unread msgs from the node
|
sync_msgs : gets all unread msgs from the node
|
||||||
wait_msg : wait for a message
|
wait_msg : wait for a message and read it
|
||||||
advert : sends advert
|
advert : sends advert
|
||||||
contacts : gets contact list
|
contacts : gets contact list
|
||||||
share_contact
|
share_contact <ct> : share a contact with others
|
||||||
remove_contact
|
remove_contact <ct> : removes a contact from this node
|
||||||
reset_path
|
reset_path <ct> : resets path to a contact to flood
|
||||||
change_path <path>
|
change_path <ct> <path> : change the path to a contact
|
||||||
sync_time : sync time with system
|
get_time : gets current time
|
||||||
set_time <epoch> : sets time to given epoch
|
set_time <epoch> : sets time to given epoch
|
||||||
get_time : gets current time
|
sync_time : sync time with system
|
||||||
set_name <name> : sets node name
|
set_name <name> : sets node name
|
||||||
get_bat : gets battery level
|
get_bat : gets battery level
|
||||||
login <name> <pwd> : log into a node (repeater) with given pwd
|
login <name> <pwd> : log into a node (repeater) with given pwd
|
||||||
wait_login : wait for login (timeouts after 5sec)
|
wait_login : wait for login (timeouts after 5sec)
|
||||||
cmd <name> <cmd> : sends a command to a repeater
|
cmd <name> <cmd> : sends a command to a repeater (no ack)
|
||||||
req_status <name> : requests status from a node
|
req_status <name> : requests status from a node
|
||||||
sleep <secs> : sleeps for a given amount of secs""")
|
wait_status : wait and print reply
|
||||||
|
sleep <secs> : sleeps for a given amount of secs""")
|
||||||
async def main(argv):
|
|
||||||
""" Do the job """
|
async def main(argv):
|
||||||
|
""" Do the job """
|
||||||
address = ADDRESS
|
address = ADDRESS
|
||||||
port = 5000
|
port = 5000
|
||||||
hostname = None
|
hostname = None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue