|
@@ -49,6 +49,8 @@ CMD_WAITFOR = 2 # arg: (length): waits for length seconds |
|
|
CMD_RUNFOR = 3 # arg: (chan, length): turns on chan for length seconds |
|
|
CMD_RUNFOR = 3 # arg: (chan, length): turns on chan for length seconds |
|
|
CMD_PING = 4 # arg: (): a no op command |
|
|
CMD_PING = 4 # arg: (): a no op command |
|
|
CMD_SETUNSET = 5 # arg: (chan, val): sets chan to val |
|
|
CMD_SETUNSET = 5 # arg: (chan, val): sets chan to val |
|
|
|
|
|
CMD_ADV = 6 # arg: ([cnt]): advances to the next cnt (default 1) command |
|
|
|
|
|
CMD_CLEAR = 7 # arg: (): clears all future commands, but keeps current running |
|
|
|
|
|
|
|
|
class LORANode(object): |
|
|
class LORANode(object): |
|
|
'''Implement a LORANode initiator.''' |
|
|
'''Implement a LORANode initiator.''' |
|
@@ -128,6 +130,15 @@ class LORANode(object): |
|
|
async def ping(self): |
|
|
async def ping(self): |
|
|
return await self._sendcmd(CMD_PING) |
|
|
return await self._sendcmd(CMD_PING) |
|
|
|
|
|
|
|
|
|
|
|
async def adv(self, cnt=None): |
|
|
|
|
|
args = () |
|
|
|
|
|
if cnt is not None: |
|
|
|
|
|
args = (cnt, ) |
|
|
|
|
|
return await self._sendcmd(CMD_ADV, *args) |
|
|
|
|
|
|
|
|
|
|
|
async def clear(self): |
|
|
|
|
|
return await self._sendcmd(CMD_CLEAR) |
|
|
|
|
|
|
|
|
async def terminate(self): |
|
|
async def terminate(self): |
|
|
return await self._sendcmd(CMD_TERMINATE) |
|
|
return await self._sendcmd(CMD_TERMINATE) |
|
|
|
|
|
|
|
@@ -223,6 +234,8 @@ async def main(): |
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser() |
|
|
parser = argparse.ArgumentParser() |
|
|
|
|
|
|
|
|
|
|
|
parser.add_argument('-f', dest='schedfile', metavar='filename', type=str, |
|
|
|
|
|
help='Use commands from the file. One command per line.') |
|
|
parser.add_argument('-r', dest='client', metavar='module:function', type=str, |
|
|
parser.add_argument('-r', dest='client', metavar='module:function', type=str, |
|
|
help='Create a respondant instead of sending commands. Commands will be passed to the function.') |
|
|
help='Create a respondant instead of sending commands. Commands will be passed to the function.') |
|
|
parser.add_argument('-s', dest='shared_key', metavar='shared_key', type=str, required=True, |
|
|
parser.add_argument('-s', dest='shared_key', metavar='shared_key', type=str, required=True, |
|
@@ -289,18 +302,32 @@ async def main(): |
|
|
|
|
|
|
|
|
await l.start() |
|
|
await l.start() |
|
|
|
|
|
|
|
|
valid_cmds = { 'waitfor', 'setunset', 'runfor', 'ping', 'terminate', } |
|
|
|
|
|
|
|
|
valid_cmds = { |
|
|
|
|
|
'waitfor', 'setunset', 'runfor', 'ping', 'adv', 'clear', |
|
|
|
|
|
'terminate', |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if args.args and args.schedfile: |
|
|
|
|
|
parser.error('only one of -f or arguments can be specified.') |
|
|
|
|
|
|
|
|
|
|
|
if args.args: |
|
|
|
|
|
cmds = list(args.args) |
|
|
|
|
|
cmdargs = [] |
|
|
|
|
|
while cmds: |
|
|
|
|
|
a, cmds = listsplit(cmds, '--') |
|
|
|
|
|
cmdargs.append(a) |
|
|
|
|
|
else: |
|
|
|
|
|
with open(args.schedfile) as fp: |
|
|
|
|
|
cmdargs = [ x.split() for x in fp.readlines() ] |
|
|
|
|
|
|
|
|
cmdargs = list(args.args) |
|
|
|
|
|
while cmdargs: |
|
|
while cmdargs: |
|
|
cmd = cmdargs.pop(0) |
|
|
|
|
|
|
|
|
cmd, *args = cmdargs.pop(0) |
|
|
|
|
|
|
|
|
if cmd not in valid_cmds: |
|
|
if cmd not in valid_cmds: |
|
|
print('invalid command:', repr(cmd)) |
|
|
print('invalid command:', repr(cmd)) |
|
|
sys.exit(1) |
|
|
sys.exit(1) |
|
|
|
|
|
|
|
|
fun = getattr(l, cmd) |
|
|
fun = getattr(l, cmd) |
|
|
args, cmdargs = listsplit(cmdargs, '--') |
|
|
|
|
|
|
|
|
|
|
|
await fun(*(int(x) for x in args)) |
|
|
await fun(*(int(x) for x in args)) |
|
|
|
|
|
|
|
|