Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ language: python
python:
- "3.4"
- "3.5"
before_install:
- sudo apt-get -qq update
- sudo apt-get install -y libow-dev
install:
- pip install --upgrade pytest pytest-mock pytest-cov coveralls
- pip install -r dev-requirements.txt
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pytest-isort
pytest-mock
pytest-pylint
pytest-runner
onewire
pyudev
yapf
requests
2 changes: 1 addition & 1 deletion labgrid/driver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .sshdriver import SSHDriver
from .externalconsoledriver import ExternalConsoleDriver
from .exception import CleanUpError, ExecutionError
from .powerdriver import ManualPowerDriver, ExternalPowerDriver
from .powerdriver import ManualPowerDriver, ExternalPowerDriver, DigitalOutputPowerDriver
from .usbloader import MXSUSBDriver, IMXUSBDriver
from .usbstorage import USBStorageDriver
from .infodriver import InfoDriver
Expand Down
29 changes: 29 additions & 0 deletions labgrid/driver/onewiredriver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import logging
import onewire

import attr

from ..factory import target_factory
from ..resource import OneWirePIO
from ..protocol import DigitalOutputProtocol
from .common import Driver

@target_factory.reg_driver
@attr.s
class OneWirePIODriver(Driver, DigitalOutputProtocol):

bindings = {"port": OneWirePIO, }

def __attrs_post_init__(self):
super().__attrs_post_init__()
self.onewire = onewire.Onewire(self.port.host)

def set(self, status):
if status == True:
self.onewire.set(self.port.path, '1')
else:
self.onewire.set(self.port.path, '0')

def get(self):
status = self.onewire.get(self.port.path)
return status == '1'
29 changes: 28 additions & 1 deletion labgrid/driver/powerdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import attr

from ..factory import target_factory
from ..protocol import PowerProtocol
from ..protocol import PowerProtocol, DigitalOutputProtocol
from ..resource import NetworkPowerPort
from .common import Driver
from .onewiredriver import OneWirePIODriver


@target_factory.reg_driver
Expand Down Expand Up @@ -93,3 +94,29 @@ def fallback():
def get(self):
return self.backend.get(self.port.host, self.port.index)

@target_factory.reg_driver
@attr.s
class DigitalOutputPowerDriver(Driver, PowerProtocol):
"""DigitalOutputPowerDriver - Driver using a DigitalOutput to reset the target and
subprocesses to turn it on and off"""
bindings = {"output": DigitalOutputProtocol, }
cmd_on = attr.ib(validator=attr.validators.instance_of(str))
cmd_off = attr.ib(validator=attr.validators.instance_of(str))
delay = attr.ib(default=1.0, validator=attr.validators.instance_of(float))

def __attrs_post_init__(self):
super().__attrs_post_init__()

def on(self):
subprocess.check_call(self.cmd_on)

def off(self):
subprocess.check_call(self.cmd_off)

def cycle(self):
self.output.set(True)
time.sleep(self.delay)
self.output.set(False)

def get(self):
return True
1 change: 1 addition & 0 deletions labgrid/protocol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from .powerprotocol import PowerProtocol
from .filetransferprotocol import FileTransferProtocol
from .infoprotocol import InfoProtocol
from .digitaloutputprotocol import DigitalOutputProtocol
15 changes: 15 additions & 0 deletions labgrid/protocol/digitaloutputprotocol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import abc


class DigitalOutputProtocol(abc.ABC):
"""Abstract class providing the OneWireProtocol interface"""

@abc.abstractmethod
def get(self):
"""Implementations should return the status of the OneWirePort."""
raise NotImplementedError

@abc.abstractmethod
def set(self, status):
"""Implementations should set the status of the OneWirePort"""
raise NotImplementedError
1 change: 1 addition & 0 deletions labgrid/resource/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .base import SerialPort
from .serialport import RawSerialPort
from .networkservice import NetworkService
from .onewireport import OneWirePIO
from .power import NetworkPowerPort
from .udev import USBSerialPort
from .common import Resource, ResourceManager, ManagedResource
16 changes: 16 additions & 0 deletions labgrid/resource/onewireport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import attr

from ..factory import target_factory
from .common import Resource


@target_factory.reg_resource
@attr.s
class OneWirePIO(Resource):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a docstring with example host/port values.

"""This resource describes a Onewire PIO Port.

Arguments:
host - The hostname of the owserver e.g. localhost:4304
path - Path to the port on the owserver e.g. 29.7D6913000000/PIO.0"""
host = attr.ib(validator=attr.validators.instance_of(str))
path = attr.ib(validator=attr.validators.instance_of(str))
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'pytest',
'pyyaml',
'pyudev',
'onewire',
'requests',
],
packages=[
Expand Down