forked from scriptorron/indi_pylibcamera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SnoopingManager.py
83 lines (71 loc) · 2.84 KB
/
SnoopingManager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""
Snooping manager
"""
import logging
class SnoopingManager:
def __init__(self, to_server_func):
self.to_server = to_server_func
# snooped values: dict(device->dict(name->dict(elements)))
self.snoopedValues = dict()
# kind->device table
self.DevicesOfKind = dict()
def start_Snooping(self, kind: str, device: str, names: list):
"""start snooping of a different driver
Args:
kind: type/kind of driver (mount, focusser, ...)
device: device name to snoop
names: vector names to snoop
"""
if kind in self.DevicesOfKind:
if device != self.DevicesOfKind[kind]:
# snoop now a different device -> stop snooping of old device
self.stop_Snooping(kind)
self.DevicesOfKind[kind] = device
if device not in self.snoopedValues:
self.snoopedValues[device] = dict()
for name in names:
if name not in self.snoopedValues[device]:
self.snoopedValues[device][name] = dict()
# send request to server
xml = f'<getProperties version="1.7" device="{device}" name="{name}" />'
self.to_server(xml)
def stop_Snooping(self, kind: str):
"""stop snooping for given driver kind/type
"""
if kind in self.DevicesOfKind:
device = self.DevicesOfKind[kind]
del self.snoopedValues[device]
del self.DevicesOfKind[kind]
def catching(self, device: str, name: str, values: dict):
"""catch values from a snooped device
Args:
device: device which is snooped (or not)
name: vector name
values: dict(element->value)
"""
if device in self.snoopedValues:
if name in self.snoopedValues[device]:
self.snoopedValues[device][name] = values
logging.debug(f'snooped "{device}" - "{name}": {values}')
def get_Elements(self, kind: str, name: str):
"""get elements of snooped vector with given kind
Args:
kind: kind/type of snooped device (mount, focusser, ...)
name: vector name
Returns:
dict of vector elements and their values (strings!)
empty dict if not snooped or nothing received yet
"""
if kind in self.DevicesOfKind:
device = self.DevicesOfKind[kind]
return self.snoopedValues[device].get(name, dict())
else:
return dict()
def __str__(self):
"""make string representation of snooped values
"""
snooped = []
for device, deviceProps in self.snoopedValues.items():
for name, elements in deviceProps.items():
snooped.append(f'"{device}" - "{name}": {elements}')
return "\n".join(snooped)