82 lines
1.6 KiB
Python
82 lines
1.6 KiB
Python
|
from cmdline import Cmdline
|
||
|
|
||
|
monoid = 0
|
||
|
|
||
|
def genid():
|
||
|
monoid = monoid + 1
|
||
|
return f":{monoid}"
|
||
|
|
||
|
class Command:
|
||
|
def write_start(self):
|
||
|
return "" if self.id is None else f"{self.id}\t"
|
||
|
def exec(self):
|
||
|
pass
|
||
|
|
||
|
# A set of ids that the command releases
|
||
|
def releasing(self):
|
||
|
return set()
|
||
|
# A set of channels the command accesses
|
||
|
def accessing(self):
|
||
|
return set()
|
||
|
# A dictionary of (id, channel) associated with the command
|
||
|
def getids(self):
|
||
|
pass
|
||
|
def __init__(self, id, is_async):
|
||
|
self.id = genid() if id is None else id
|
||
|
self.is_async = is_async
|
||
|
|
||
|
class WaitCommand(Command):
|
||
|
def exec(self):
|
||
|
ids = self.ids
|
||
|
while len(ids) > 0:
|
||
|
x = self.getline()
|
||
|
if x.id in ids:
|
||
|
ids.remove(x.id)
|
||
|
|
||
|
return None
|
||
|
|
||
|
def releasing(self):
|
||
|
return self.ids
|
||
|
|
||
|
def __init__(self, ids, getline):
|
||
|
Command.__init__(self, None, False)
|
||
|
self.ids = ids
|
||
|
self.getline = getline
|
||
|
|
||
|
class RampCommand(Command):
|
||
|
def exec(self):
|
||
|
s = f"{self.write_start()}RAMP"
|
||
|
for (ch, start, step, end, interval) in self.listing:
|
||
|
s = s + f"\t{ch}\t{end}\t{start}\t{interval}\t{step}"
|
||
|
s = s + "\n"
|
||
|
return s
|
||
|
|
||
|
def getids(self):
|
||
|
d = {}
|
||
|
for c in self.listing:
|
||
|
d[f"{self.id}.{c[0]}"] = c[0]
|
||
|
return d
|
||
|
|
||
|
def accessing(self):
|
||
|
return self.listing
|
||
|
|
||
|
def __init__(self, id, listing):
|
||
|
Command.__init__(self, id, True)
|
||
|
self.listing = listing
|
||
|
|
||
|
class SetCommand(Command):
|
||
|
def exec(self):
|
||
|
s = f"{self.write_start()}SET\t{self.ch}\t{self.val}\n"
|
||
|
return set()
|
||
|
|
||
|
def getids(self):
|
||
|
return {self.id : self.ch}
|
||
|
|
||
|
def accessing(self):
|
||
|
return set([self.val])
|
||
|
|
||
|
def __init__(self, ser, id, ch, val):
|
||
|
Command.__init__(self, id, False)
|
||
|
self.ch = ch
|
||
|
self.val = val
|