-
Notifications
You must be signed in to change notification settings - Fork 3
/
lxatac-eet.py
62 lines (47 loc) · 1.9 KB
/
lxatac-eet.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
import os.path
import attr
from labgrid import step, target_factory
from labgrid.driver import Driver
from labgrid.resource.common import NetworkResource, Resource
from labgrid.util.agentwrapper import AgentWrapper
@target_factory.reg_resource
@attr.s(eq=False)
class LxatacEETResource(Resource):
"""This resource describes a LXA-TAC external electrical testing device connected via USB/I2C.
Args:
usbpath (str): Name of the i2c-tiny-usb device as found in /sys/class/i2c-adapter/i2c-*/name"""
usbpath = attr.ib(validator=attr.validators.instance_of(str))
@target_factory.reg_resource
@attr.s(eq=False)
class RemoteLxatacEETResource(NetworkResource):
"""This resource describes a LXA-TAC external electrical testing device connected via USB/I2C.
Args:
host (str): hostname of the exporter
usbpath (str): Name of the i2c-tiny-usb device as found in /sys/class/i2c-adapter/i2c-*/name"""
host = attr.ib(validator=attr.validators.instance_of(str))
usbpath = attr.ib(validator=attr.validators.instance_of(str))
@target_factory.reg_driver
@attr.s(eq=False)
class LxatacEETDriver(Driver):
bindings = {
"eet": {"LxatacEETResource", "RemoteLxatacEETResource"},
}
def __attrs_post_init__(self):
super().__attrs_post_init__()
self.wrapper = None
def on_activate(self):
host = self.eet.host if isinstance(self.eet, RemoteLxatacEETResource) else None
self.wrapper = AgentWrapper(host)
self.proxy = self.wrapper.load(
"lxatac-eet", path=os.path.join(os.path.dirname(os.path.realpath(__file__)), "agents")
)
self.proxy.init(self.eet.usbpath)
def on_deactivate(self):
self.proxy.link("")
self.wrapper.close()
self.wrapper = None
self.proxy = None
@Driver.check_active
@step(args=["linkspec"])
def link(self, linkspec):
self.proxy.link(linkspec)