added modulo/offset to BSCache.get_var()
This commit is contained in:
34
bscache.py
34
bscache.py
@ -7,7 +7,7 @@ from prodthread import ProdThread
|
||||
class BSCache:
|
||||
|
||||
def __init__(self):
|
||||
self.channels = set()
|
||||
self.channels = {}
|
||||
self.data = None
|
||||
self.pt = ProdThread(self.run)
|
||||
|
||||
@ -22,8 +22,9 @@ class BSCache:
|
||||
|
||||
|
||||
def run(self, queue, running):
|
||||
channels = self.channels
|
||||
with source(channels=channels, receive_timeout=-1) as src:
|
||||
channels = self.channels.keys()
|
||||
configs = self.channels.values()
|
||||
with source(channels=configs, receive_timeout=-1) as src:
|
||||
while running.is_set():
|
||||
msg = src.receive()
|
||||
data = repack(channels, msg)
|
||||
@ -31,21 +32,21 @@ class BSCache:
|
||||
queue.put(data)
|
||||
|
||||
|
||||
def stop(self, *args):
|
||||
print("\n\nstopping\n\n", args)
|
||||
def stop(self):
|
||||
self.pt.stop()
|
||||
|
||||
|
||||
def get_var(self, name):
|
||||
def get_var(self, name, modulo=None, offset=None):
|
||||
if name is not "pid" and not name in self.channels:
|
||||
self.update_source(name)
|
||||
cfg = make_channel_config(name, modulo, offset)
|
||||
self.update_source(name, cfg)
|
||||
return BSVar(name, self)
|
||||
|
||||
|
||||
def update_source(self, name):
|
||||
def update_source(self, name, cfg):
|
||||
self.pt.stop()
|
||||
print("add channel", name)
|
||||
self.channels.add(name)
|
||||
self.channels[name] = cfg
|
||||
self.pt.start()
|
||||
|
||||
while self.data is None or name not in self.data:
|
||||
@ -56,6 +57,21 @@ class BSCache:
|
||||
|
||||
|
||||
|
||||
def make_channel_config(name, modulo, offset):
|
||||
res = {}
|
||||
if modulo is not None:
|
||||
res["modulo"] = modulo
|
||||
if offset is not None:
|
||||
res["offset"] = offset
|
||||
if not res:
|
||||
return name
|
||||
res["name"] = name
|
||||
return res
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def repack(channels, message):
|
||||
data = message.data.data
|
||||
pulse_id = message.data.pulse_id
|
||||
|
Reference in New Issue
Block a user