class PigweedDevice:
    def __init__(self, device_tty, baud, platform_module=None, platform_args=None):
        self.pw_rpc_client = HdlcRpcClient(serial.Serial(device_tty, baud), [PROTO])
        self._platform = None
        print("Platform args: %s" % platform_args)
        print("Platform module: %s" % platform_module)
        if platform_module:
            m = importlib.import_module(platform_module)
            create_platform_method = getattr(m, "create_platform")
            self._platform = create_platform_method(platform_args)

    def rpcs(self):
        return self.pw_rpc_client.rpcs().pw.rpc

    @property
    def platform(self):
        return self._platform
class PigweedDevice:
    def __init__(self, device_tty, baud, platform_module=None, platform_args=None):
        ser = serial.Serial(device_tty, baud, timeout=0.01)
        self.pw_rpc_client = HdlcRpcClient(lambda: ser.read(4096),
                                           [PROTO], default_channels(ser.write))
        self._platform = None
        print("Platform args: %s" % platform_args)
        print("Platform module: %s" % platform_module)
        if platform_module:
            m = importlib.import_module(platform_module)
            create_platform_method = getattr(m, "create_platform")
            self._platform = create_platform_method(platform_args)

    def rpcs(self):
        return self.pw_rpc_client.rpcs().pw.rpc

    @property
    def platform(self):
        return self._platform
Beispiel #3
0
def script(device: str, baud: int) -> None:
    # Set up a pw_rpc client that uses HDLC.
    ser = serial.Serial(device, baud, timeout=0.01)
    client = HdlcRpcClient(lambda: ser.read(4096), [PROTO],
                           default_channels(ser.write))

    # Make a shortcut to the EchoService.
    echo_service = client.rpcs().pw.rpc.EchoService

    # Call some RPCs and check the results.
    status, payload = echo_service.Echo(msg='Hello')

    if status.ok():
        print('The status was', status)
        print('The payload was', payload)
    else:
        print('Uh oh, this RPC returned', status)

    status, payload = echo_service.Echo(msg='Goodbye!')

    print('The device says:', payload.msg)
Beispiel #4
0
class PigweedClient:
    def __init__(self, device, protos):
        """
        Pigweed Client class containing RPC client initialization and service functions
        Create HdlcRpcCLient object and redirect serial communication to it
        :param device: test device instance
        :param protos: array of RPC protocols
        """
        self.device = device
        self.device.stop()
        self.last_timeout = self.device.serial.get_timeout()
        self.device.serial.set_timeout(0.01)
        self._pw_rpc_client = HdlcRpcClient(
            lambda: self.device.serial.read(4096), protos,
            default_channels(self.device.serial.write))
        self._rpcs = self._pw_rpc_client.rpcs()

    def __del__(self):
        self.device.serial.set_timeout(self.last_timeout)
        self.device.start()

    @property
    def rpcs(self):
        return self._rpcs