mirror of
https://github.com/meshcore-dev/meshcore-cli.git
synced 2026-04-20 22:13:48 +00:00
chaining commands
This commit is contained in:
parent
35e0edc684
commit
da1363a6fa
1 changed files with 30 additions and 16 deletions
46
mc-cli.py
46
mc-cli.py
|
|
@ -143,7 +143,7 @@ class MeshCore:
|
||||||
return self.time
|
return self.time
|
||||||
|
|
||||||
async def set_time(self, val):
|
async def set_time(self, val):
|
||||||
return await self.send(b"\x06" + val.to_bytes(4, 'little'))
|
return await self.send(b"\x06" + int(val).to_bytes(4, 'little'))
|
||||||
|
|
||||||
async def get_contacts(self):
|
async def get_contacts(self):
|
||||||
return await self.send(b"\x04")
|
return await self.send(b"\x04")
|
||||||
|
|
@ -170,16 +170,9 @@ async def test(mc):
|
||||||
print("\nSending msg")
|
print("\nSending msg")
|
||||||
print(await mc.send_msg( b"\xd6\xe4?\x8e\x9e\xf2","coucou"))
|
print(await mc.send_msg( b"\xd6\xe4?\x8e\x9e\xf2","coucou"))
|
||||||
|
|
||||||
async def main(args):
|
async def next_cmd(mc, cmds):
|
||||||
|
argnum = 0
|
||||||
mc = MeshCore(ADDRESS)
|
match cmds[0] :
|
||||||
await mc.connect()
|
|
||||||
|
|
||||||
if len(args) < 2:
|
|
||||||
print("Commands : send, sendto, recv, contacts, infos")
|
|
||||||
return
|
|
||||||
|
|
||||||
match args[1] :
|
|
||||||
case "test" :
|
case "test" :
|
||||||
await test(mc)
|
await test(mc)
|
||||||
case "get_time" :
|
case "get_time" :
|
||||||
|
|
@ -190,12 +183,15 @@ async def main(args):
|
||||||
case "sync_time" :
|
case "sync_time" :
|
||||||
print(await mc.set_time(int(time.time())))
|
print(await mc.set_time(int(time.time())))
|
||||||
case "set_time" :
|
case "set_time" :
|
||||||
print(await mc.set_time(argv[2]))
|
argnum = 1
|
||||||
|
print(await mc.set_time(cmds[1]))
|
||||||
case "send" :
|
case "send" :
|
||||||
print(await mc.send_msg(bytes.fromhex(args[2]), args[3]))
|
argnum = 2
|
||||||
|
print(await mc.send_msg(bytes.fromhex(cmds[1]), cmds[2]))
|
||||||
case "sendto" : # sends to a name (need to get contacts first so can take time, contacts should be cached to file ...)
|
case "sendto" : # sends to a name (need to get contacts first so can take time, contacts should be cached to file ...)
|
||||||
|
argnum = 2
|
||||||
await mc.get_contacts()
|
await mc.get_contacts()
|
||||||
print(await mc.send_msg(bytes.fromhex(mc.contacts[args[2]]["public_key"])[0:6], args[3]))
|
print(await mc.send_msg(bytes.fromhex(mc.contacts[cmds[1]]["public_key"])[0:6], cmds[2]))
|
||||||
case "contacts" :
|
case "contacts" :
|
||||||
print(json.dumps(await mc.get_contacts(),indent=4))
|
print(json.dumps(await mc.get_contacts(),indent=4))
|
||||||
case "recv" :
|
case "recv" :
|
||||||
|
|
@ -205,8 +201,26 @@ async def main(args):
|
||||||
case "advert" :
|
case "advert" :
|
||||||
print(await mc.send_advert())
|
print(await mc.send_advert())
|
||||||
case "set_name" :
|
case "set_name" :
|
||||||
print(await mc.set_name(args[2]))
|
argnum = 1
|
||||||
|
print(await mc.set_name(cmds[1]))
|
||||||
case "sleep" :
|
case "sleep" :
|
||||||
await asyncio.sleep(int(args[2]))
|
argnum = 1
|
||||||
|
await asyncio.sleep(int(cmds[1]))
|
||||||
|
|
||||||
|
print (f"cmd {cmds[0:argnum+1]} processed ...")
|
||||||
|
return cmds[argnum+1:]
|
||||||
|
|
||||||
|
async def main(args):
|
||||||
|
|
||||||
|
if len(args) < 2:
|
||||||
|
print("Commands : send, sendto, recv, contacts, infos")
|
||||||
|
return
|
||||||
|
|
||||||
|
mc = MeshCore(ADDRESS)
|
||||||
|
await mc.connect()
|
||||||
|
|
||||||
|
cmds = args[1:]
|
||||||
|
while len(cmds)>0 :
|
||||||
|
cmds = await next_cmd(mc, cmds)
|
||||||
|
|
||||||
asyncio.run(main(sys.argv))
|
asyncio.run(main(sys.argv))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue