Simran Basi | a9f4103 | 2012-05-11 14:21:58 -0700 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | """Servo Server.""" |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 5 | import logging |
Ruben Rodriguez Buchillon | 529b0de | 2020-03-20 18:33:36 -0700 | [diff] [blame] | 6 | import os |
| 7 | import re |
| 8 | try: |
| 9 | from SimpleXMLRPCServer import SimpleXMLRPCServer |
| 10 | except ImportError: |
| 11 | from xmlrpc.server import SimpleXMLRPCServer |
| 12 | # TODO(crbug.com/999878): This is for python3 compatibility. |
| 13 | # Remove once fully moved to python3. |
| 14 | import time |
| 15 | import usb |
Matthew Blecker | 6b250ff | 2020-08-23 12:00:55 -0700 | [diff] [blame] | 16 | import weakref |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 17 | |
Ruben Rodriguez Buchillon | 4386b62 | 2020-11-18 14:00:13 -0800 | [diff] [blame] | 18 | from . import drv as servo_drv |
| 19 | from . import interface as _interface |
| 20 | from . import servo_dev |
| 21 | from . import servo_interfaces |
| 22 | from . import servo_logging |
| 23 | from . import servo_postinit |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 24 | |
Wai-Hong Tam | 4c09eff | 2017-02-17 11:46:19 -0800 | [diff] [blame] | 25 | HwDriverError = servo_drv.hw_driver.HwDriverError |
Aseda Aboagye | a492221 | 2015-11-20 15:19:08 -0800 | [diff] [blame] | 26 | |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 27 | |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 28 | class ServodError(Exception): |
| 29 | """Exception class for servod.""" |
| 30 | |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 31 | |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 32 | class Servod(object): |
| 33 | """Main class for Servo debug/controller Daemon.""" |
Simran Basi | a9f4103 | 2012-05-11 14:21:58 -0700 | [diff] [blame] | 34 | |
Kevin Cheng | 4b4f002 | 2016-09-09 02:37:07 -0700 | [diff] [blame] | 35 | # This is the key to get the main serial used in the _serialnames dict. |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 36 | MAIN_SERIAL = 'main' |
| 37 | SERVO_MICRO_SERIAL = 'servo_micro' |
Matthew Blecker | 8ce0ddc | 2020-11-02 17:19:25 -0800 | [diff] [blame] | 38 | C2D2_SERIAL = 'c2d2' |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 39 | CCD_SERIAL = 'ccd' |
Kevin Cheng | 4b4f002 | 2016-09-09 02:37:07 -0700 | [diff] [blame] | 40 | |
Ruben Rodriguez Buchillon | a5d8b92 | 2018-09-03 16:51:03 +0800 | [diff] [blame] | 41 | # Timeout to wait for interfaces to become available again if reinitialization |
Mary Ruthven | b7cc554 | 2019-07-15 15:20:10 -0700 | [diff] [blame] | 42 | # is taking place. In seconds. This is supposed to recover from brief resets. |
| 43 | # If the interface disappears for more than 5 seconds, then someone probably |
| 44 | # intentionally disconnected the device. Servod shouldn't be responsible for |
| 45 | # waiting for the device during an intentional disconnect. |
| 46 | INTERFACE_AVAILABILITY_TIMEOUT = 5 |
Ruben Rodriguez Buchillon | a5d8b92 | 2018-09-03 16:51:03 +0800 | [diff] [blame] | 47 | |
Dana Goyette | 4a61e90 | 2020-05-08 10:09:31 -0700 | [diff] [blame] | 48 | # Exceptions to count as known or ordinary. Any errors that aren't instances |
| 49 | # of these (or their subclasses) will be logged with "Please take a look." |
| 50 | KNOWN_EXCEPTIONS = (AttributeError, NameError, HwDriverError) |
| 51 | |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 52 | def init_servo_interfaces(self, vendor, product, serialname, interfaces): |
Kevin Cheng | dc3befd | 2016-07-15 12:34:00 -0700 | [diff] [blame] | 53 | """Init the servo interfaces with the given interfaces. |
| 54 | |
| 55 | We don't use the self._{vendor,product,serialname} attributes because we |
| 56 | want to allow other callers to initialize other interfaces that may not |
| 57 | be associated with the initialized attributes (e.g. a servo v4 servod object |
| 58 | that wants to also initialize a servo micro interface). |
| 59 | |
| 60 | Args: |
| 61 | vendor: USB vendor id of FTDI device. |
| 62 | product: USB product id of FTDI device. |
| 63 | serialname: String of device serialname/number as defined in FTDI |
| 64 | eeprom. |
| 65 | interfaces: List of strings of interface types the server will |
| 66 | instantiate. |
| 67 | |
| 68 | Raises: |
| 69 | ServodError if unable to locate init method for particular interface. |
| 70 | """ |
Mary Ruthven | 1338964 | 2017-02-14 12:15:34 -0800 | [diff] [blame] | 71 | # If it is a new device add it to the list |
Wai-Hong Tam | 1f9e9a7 | 2017-05-02 14:14:46 -0700 | [diff] [blame] | 72 | device = (vendor, product, serialname) |
Mary Ruthven | cb86185 | 2019-07-15 16:30:48 -0700 | [diff] [blame] | 73 | self.add_device(device) |
Mary Ruthven | 1338964 | 2017-02-14 12:15:34 -0800 | [diff] [blame] | 74 | |
Kevin Cheng | dc3befd | 2016-07-15 12:34:00 -0700 | [diff] [blame] | 75 | # Extend the interface list if we need to. |
| 76 | interfaces_len = len(interfaces) |
| 77 | interface_list_len = len(self._interface_list) |
| 78 | if interfaces_len > interface_list_len: |
Ruben Rodriguez Buchillon | 1092ebf | 2020-02-28 15:12:19 -0800 | [diff] [blame] | 79 | # Fill with dummies. |
Sam Hurst | 2b48753 | 2020-08-05 11:00:23 -0700 | [diff] [blame] | 80 | self._interface_list += [_interface.empty.Empty()] * (interfaces_len - |
Ruben Rodriguez Buchillon | 1092ebf | 2020-02-28 15:12:19 -0800 | [diff] [blame] | 81 | interface_list_len) |
Kevin Cheng | dc3befd | 2016-07-15 12:34:00 -0700 | [diff] [blame] | 82 | |
Ruben Rodriguez Buchillon | 1092ebf | 2020-02-28 15:12:19 -0800 | [diff] [blame] | 83 | for i, interface_data in enumerate(interfaces): |
| 84 | if type(interface_data) is dict: |
| 85 | name = interface_data['name'] |
Kevin Cheng | dc3befd | 2016-07-15 12:34:00 -0700 | [diff] [blame] | 86 | # Store interface index for those that care about it. |
Ruben Rodriguez Buchillon | 1092ebf | 2020-02-28 15:12:19 -0800 | [diff] [blame] | 87 | interface_data['index'] = i |
| 88 | elif type(interface_data) is str: |
Sam Hurst | 2b48753 | 2020-08-05 11:00:23 -0700 | [diff] [blame] | 89 | if interface_data in ['empty', 'ftdi_empty']: |
| 90 | # 'empty' reserves the interface for future use. Typically the |
Ruben Rodriguez Buchillon | 78c2349 | 2019-06-18 13:55:21 -0700 | [diff] [blame] | 91 | # interface will be managed by external third-party tools like |
| 92 | # openOCD for JTAG or flashrom for SPI. In the case of servo V4, |
| 93 | # it serves as a placeholder for servo micro interfaces. |
| 94 | continue |
Ruben Rodriguez Buchillon | 1092ebf | 2020-02-28 15:12:19 -0800 | [diff] [blame] | 95 | name = interface_data |
Kevin Cheng | dc3befd | 2016-07-15 12:34:00 -0700 | [diff] [blame] | 96 | else: |
Ruben Rodriguez Buchillon | 1092ebf | 2020-02-28 15:12:19 -0800 | [diff] [blame] | 97 | raise ServodError('Illegal interface data type %s' |
| 98 | % type(interface_data)) |
Kevin Cheng | dc3befd | 2016-07-15 12:34:00 -0700 | [diff] [blame] | 99 | |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 100 | self._logger.info('Initializing interface %d to %s', i, name) |
Ruben Rodriguez Buchillon | 1092ebf | 2020-02-28 15:12:19 -0800 | [diff] [blame] | 101 | result = _interface.Build(name=name, index=i, vid=vendor, pid=product, |
| 102 | sid=serialname, interface_data=interface_data, |
| 103 | servod=self) |
Kevin Cheng | dc3befd | 2016-07-15 12:34:00 -0700 | [diff] [blame] | 104 | if isinstance(result, tuple): |
| 105 | result_len = len(result) |
Wai-Hong Tam | d8a94d6 | 2017-04-28 10:11:51 -0700 | [diff] [blame] | 106 | self._interface_list[i:(i + result_len)] = result |
Kevin Cheng | dc3befd | 2016-07-15 12:34:00 -0700 | [diff] [blame] | 107 | else: |
Wai-Hong Tam | d8a94d6 | 2017-04-28 10:11:51 -0700 | [diff] [blame] | 108 | self._interface_list[i] = result |
Kevin Cheng | dc3befd | 2016-07-15 12:34:00 -0700 | [diff] [blame] | 109 | |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 110 | def __init__(self, config, vendor, product, serialname=None, interfaces=None, |
Namyoon Woo | 341a833 | 2019-03-07 12:01:31 -0800 | [diff] [blame] | 111 | board='', model='', version=None, usbkm232=None): |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 112 | """Servod constructor. |
| 113 | |
| 114 | Args: |
| 115 | config: instance of SystemConfig containing all controls for |
| 116 | particular Servod invocation |
| 117 | vendor: usb vendor id of FTDI device |
| 118 | product: usb product id of FTDI device |
Todd Broch | ad03444 | 2011-05-25 15:05:29 -0700 | [diff] [blame] | 119 | serialname: string of device serialname/number as defined in FTDI eeprom. |
Todd Broch | dbb0998 | 2011-10-02 07:14:26 -0700 | [diff] [blame] | 120 | interfaces: list of strings of interface types the server will instantiate |
Namyoon Woo | 341a833 | 2019-03-07 12:01:31 -0800 | [diff] [blame] | 121 | board: board name. e.g. octopus, coral, or scarlet. |
| 122 | model: model name of a given board. e.g. fleex, ampton, or apel. |
Simran Basi | a23c139 | 2013-08-06 14:59:10 -0700 | [diff] [blame] | 123 | version: String. Servo board version. Examples: servo_v1, servo_v2, |
| 124 | servo_v2_r0, servo_v3 |
Yusuf Mohsinally | 29e30d2 | 2014-01-14 15:29:17 -0800 | [diff] [blame] | 125 | usbkm232: String. Optional. Path to USB-KM232 device which allow for |
Kevin Cheng | dc3befd | 2016-07-15 12:34:00 -0700 | [diff] [blame] | 126 | sending keyboard commands to DUTs that do not have built in |
Wai-Hong Tam | 7b9f299 | 2017-10-24 16:07:14 -0700 | [diff] [blame] | 127 | keyboards. Used in FAFT tests. Use None for on board AVR MCU. |
| 128 | e.g. '/dev/ttyUSB0' or None. |
Todd Broch | dbb0998 | 2011-10-02 07:14:26 -0700 | [diff] [blame] | 129 | |
| 130 | Raises: |
| 131 | ServodError: if unable to locate init method for particular interface |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 132 | """ |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 133 | self._logger = logging.getLogger('Servod') |
| 134 | self._logger.debug('') |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 135 | self._vendor = vendor |
| 136 | self._product = product |
Mary Ruthven | cb86185 | 2019-07-15 16:30:48 -0700 | [diff] [blame] | 137 | self._devices = {} |
Kevin Cheng | 4b4f002 | 2016-09-09 02:37:07 -0700 | [diff] [blame] | 138 | self._serialnames = {self.MAIN_SERIAL: serialname} |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 139 | self._syscfg = config |
| 140 | # list of objects (Fi2c, Fgpio) to physical interfaces (gpio, i2c) that ftdi |
| 141 | # interfaces are mapped to |
| 142 | self._interface_list = [] |
| 143 | # Dict of Dict to map control name, function name to to tuple (params, drv) |
| 144 | # Ex) _drv_dict[name]['get'] = (params, drv) |
| 145 | self._drv_dict = {} |
Wai-Hong Tam | 416cf61 | 2017-09-19 11:39:21 -0700 | [diff] [blame] | 146 | self._base_board = '' |
Namyoon Woo | 341a833 | 2019-03-07 12:01:31 -0800 | [diff] [blame] | 147 | self._board = board |
| 148 | if model: |
| 149 | self._board += '_' + model |
| 150 | self._model = model |
Ruben Rodriguez Buchillon | f6e72eb | 2020-09-11 17:36:19 -0700 | [diff] [blame^] | 151 | # TODO(coconutruben): remove this caching of the 'version' after |
| 152 | # refactoring it into device properly. |
| 153 | self._base_version = version |
Simran Basi | a23c139 | 2013-08-06 14:59:10 -0700 | [diff] [blame] | 154 | self._version = version |
Yusuf Mohsinally | 29e30d2 | 2014-01-14 15:29:17 -0800 | [diff] [blame] | 155 | self._usbkm232 = usbkm232 |
Ruben Rodriguez Buchillon | 386a010 | 2018-08-16 09:11:20 +0800 | [diff] [blame] | 156 | self._keyboard = None |
| 157 | self._usb_keyboard = None |
Todd Broch | dbb0998 | 2011-10-02 07:14:26 -0700 | [diff] [blame] | 158 | if not interfaces: |
Todd Broch | b21d804 | 2014-05-15 12:54:54 -0700 | [diff] [blame] | 159 | try: |
| 160 | interfaces = servo_interfaces.INTERFACE_BOARDS[board][vendor][product] |
| 161 | except KeyError: |
| 162 | interfaces = servo_interfaces.INTERFACE_DEFAULTS[vendor][product] |
Dino Li | c89d8c8 | 2018-01-11 09:56:47 +0800 | [diff] [blame] | 163 | self._interfaces = interfaces |
Todd Broch | dbb0998 | 2011-10-02 07:14:26 -0700 | [diff] [blame] | 164 | |
Kevin Cheng | dc3befd | 2016-07-15 12:34:00 -0700 | [diff] [blame] | 165 | self.init_servo_interfaces(vendor, product, serialname, interfaces) |
Kevin Cheng | 16304d1 | 2016-07-08 11:56:55 -0700 | [diff] [blame] | 166 | servo_postinit.post_init(self) |
Ruben Rodriguez Buchillon | 16e39eb | 2020-06-24 18:06:11 -0700 | [diff] [blame] | 167 | self._syscfg.finalize() |
Danny Chan | 662b602 | 2015-11-04 17:34:53 -0800 | [diff] [blame] | 168 | |
Mary Ruthven | 1338964 | 2017-02-14 12:15:34 -0800 | [diff] [blame] | 169 | def reinitialize(self): |
| 170 | """Reinitialize all interfaces that support reinitialization""" |
Mary Ruthven | 1338964 | 2017-02-14 12:15:34 -0800 | [diff] [blame] | 171 | for i, interface in enumerate(self._interface_list): |
Ruben Rodriguez Buchillon | 1092ebf | 2020-02-28 15:12:19 -0800 | [diff] [blame] | 172 | interface.reinitialize() |
Ruben Rodriguez Buchillon | a5d8b92 | 2018-09-03 16:51:03 +0800 | [diff] [blame] | 173 | # Indicate interfaces are safe to use again. |
Mary Ruthven | cb86185 | 2019-07-15 16:30:48 -0700 | [diff] [blame] | 174 | for device in self._devices.values(): |
| 175 | device.connect() |
Mary Ruthven | 1338964 | 2017-02-14 12:15:34 -0800 | [diff] [blame] | 176 | |
Wai-Hong Tam | 4544c30 | 2017-05-24 19:44:53 -0700 | [diff] [blame] | 177 | def get_servo_interfaces(self, position, size): |
| 178 | """Get the list of servo interfaces. |
| 179 | |
| 180 | Args: |
| 181 | position: The index the first interface to get. |
| 182 | size: The number of the interfaces. |
| 183 | """ |
| 184 | return self._interface_list[position:(position + size)] |
| 185 | |
| 186 | def set_servo_interfaces(self, position, interfaces): |
| 187 | """Set the list of servo interfaces. |
| 188 | |
| 189 | Args: |
| 190 | position: The index the first interface to set. |
| 191 | interfaces: The list of interfaces to set. |
| 192 | """ |
| 193 | size = len(interfaces) |
| 194 | self._interface_list[position:(position + size)] = interfaces |
| 195 | |
Ruben Rodriguez Buchillon | a16374b | 2018-06-20 16:45:00 -0700 | [diff] [blame] | 196 | def close(self): |
| 197 | """Servod turn down logic.""" |
| 198 | for i, interface in enumerate(self._interface_list): |
Ruben Rodriguez Buchillon | 18aafeb | 2020-11-13 21:20:26 -0800 | [diff] [blame] | 199 | if not isinstance(interface, _interface.empty.Empty): |
| 200 | # Only print this on real interfaces and not place holders. |
| 201 | self._logger.info('Turning down interface %d', i) |
| 202 | interface.close() |
Todd Broch | 3ec8df0 | 2012-11-20 10:53:03 -0800 | [diff] [blame] | 203 | |
Mary Ruthven | cb86185 | 2019-07-15 16:30:48 -0700 | [diff] [blame] | 204 | def get_devices(self): |
| 205 | return self._devices.values() |
| 206 | |
| 207 | def add_device(self, device): |
| 208 | if device not in self._devices: |
| 209 | vid, pid, serial = device |
Mary Ruthven | 6b14d3f | 2019-07-15 12:52:53 -0700 | [diff] [blame] | 210 | servod_device = servo_dev.ServoDevice(vid, pid, serial) |
Mary Ruthven | cb86185 | 2019-07-15 16:30:48 -0700 | [diff] [blame] | 211 | self._devices[device] = servod_device |
| 212 | |
Tom Wai-Hong Tam | 28f0a5f | 2012-08-21 12:49:57 +0800 | [diff] [blame] | 213 | def _camel_case(self, string): |
| 214 | output = '' |
| 215 | for s in string.split('_'): |
| 216 | if output: |
| 217 | output += s.capitalize() |
| 218 | else: |
| 219 | output = s |
| 220 | return output |
| 221 | |
Wai-Hong Tam | 4544c30 | 2017-05-24 19:44:53 -0700 | [diff] [blame] | 222 | def clear_cached_drv(self): |
| 223 | """Clear the cached drivers. |
| 224 | |
| 225 | The drivers are cached in the Dict _drv_dict when a control is got or set. |
| 226 | When the servo interfaces are relocated, the cached values may become wrong. |
| 227 | Should call this method to clear the cached values. |
| 228 | """ |
| 229 | self._drv_dict = {} |
| 230 | |
Ruben Rodriguez Buchillon | 2c6589f | 2018-10-20 15:30:26 +0800 | [diff] [blame] | 231 | def _get_servo_specific_param(self, params, param_key, control_name): |
| 232 | """Get |param_key| from params by looking for servo specific params first. |
| 233 | |
| 234 | Find the candidate servos. Using servo_v4 with a servo_micro connected as |
| 235 | example, the following shows the priority for selecting the interface. |
| 236 | |
| 237 | 1. The full name. (e.g. - 'servo_v4_with_servo_micro_interface') |
| 238 | 2. servo_micro_interface |
| 239 | 3. servo_v4_interface |
| 240 | 4. Fallback to the default, interface. |
| 241 | |
| 242 | Args: |
| 243 | params: params dictionary for a control |
| 244 | param_key: identifier in the params dictionary to look for |
| 245 | control_name: control name the params correspond to |
| 246 | |
| 247 | Returns: |
| 248 | The best suited param value for param_key given the servo type or |
| 249 | None if even the default is not defined. |
| 250 | """ |
| 251 | candidates = [self._version] |
Ruben Rodriguez Buchillon | d18c6eb | 2019-07-10 14:40:22 -0700 | [diff] [blame] | 252 | if '_with_' in self._version: |
| 253 | v4, raw_dut_device = self._version.split('_with_') |
| 254 | dut_devices = raw_dut_device.split('_and_') |
| 255 | # NOTE(coconutruben): all of this nonsense is going away with the new |
| 256 | # servod and is to bridge the time until then. Please forgive the below |
| 257 | # until then. |
| 258 | if '.' in control_name: |
| 259 | # In the current implementation, the only case where a '.' (a prefix) |
| 260 | # is in the control name is when there is a dual instance with micro and |
| 261 | # ccd on a v4. |
| 262 | dut_device = dut_devices[1] |
| 263 | else: |
| 264 | # In the normal control name, we need to make sure the version used |
| 265 | # does not include the potential _and_ portion from a dual instance. |
| 266 | dut_device = dut_devices[0] |
| 267 | candidates.extend([dut_device, v4]) |
Ruben Rodriguez Buchillon | 2c6589f | 2018-10-20 15:30:26 +0800 | [diff] [blame] | 268 | candidates = ['%s_%s' % (c, param_key) for c in candidates] |
| 269 | candidates.append(param_key) |
| 270 | for c in candidates: |
| 271 | if c in params: |
| 272 | self._logger.debug('Using %s parameter.', c) |
| 273 | return params[c] |
| 274 | self._logger.error('Unable to determine %s for %s', param_key, control_name) |
| 275 | self._logger.error('params: %r', params) |
| 276 | return None |
| 277 | |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 278 | def _get_param_drv(self, control_name, is_get=True): |
| 279 | """Get access to driver for a given control. |
| 280 | |
| 281 | Note, some controls have different parameter dictionaries for 'getting' the |
| 282 | control's value versus 'setting' it. Boolean is_get distinguishes which is |
| 283 | being requested. |
| 284 | |
| 285 | Args: |
| 286 | control_name: string name of control |
| 287 | is_get: boolean to determine |
| 288 | |
| 289 | Returns: |
Fei Shao | 8aec57b | 2019-12-11 17:08:40 +0800 | [diff] [blame] | 290 | tuple (params, drv, device_info) where: |
| 291 | params: param dictionary for control |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 292 | drv: instance object of driver for particular control |
Fei Shao | 8aec57b | 2019-12-11 17:08:40 +0800 | [diff] [blame] | 293 | device_info: servo device information |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 294 | |
| 295 | Raises: |
| 296 | ServodError: Error occurred while examining params dict |
| 297 | """ |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 298 | self._logger.debug('') |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 299 | # if already setup just return tuple from driver dict |
| 300 | if control_name in self._drv_dict: |
| 301 | if is_get and ('get' in self._drv_dict[control_name]): |
| 302 | return self._drv_dict[control_name]['get'] |
| 303 | if not is_get and ('set' in self._drv_dict[control_name]): |
| 304 | return self._drv_dict[control_name]['set'] |
| 305 | |
| 306 | params = self._syscfg.lookup_control_params(control_name, is_get) |
Simran Basi | 668be0e | 2013-08-07 11:54:50 -0700 | [diff] [blame] | 307 | |
Ruben Rodriguez Buchillon | 2c6589f | 2018-10-20 15:30:26 +0800 | [diff] [blame] | 308 | # Get the most suitable drv given the servo instance. |
| 309 | drv_name = self._get_servo_specific_param(params, 'drv', control_name) |
| 310 | if drv_name == 'na': |
| 311 | # 'na' drv can be used to selectively turn controls into noops for |
| 312 | # a given servo hardware. Ensure that there is an interface. |
| 313 | params.setdefault('interface', 'servo') |
| 314 | self._logger.debug('Setting interface to default to %r for %r unless ' |
| 315 | ' defined in params, as drv is %r.', 'servo', |
| 316 | control_name, 'na') |
| 317 | # Setting input_type to str allows all inputs through enabling a true noop |
| 318 | params.update({'input_type': 'str'}) |
| 319 | interface_id = self._get_servo_specific_param(params, 'interface', |
| 320 | control_name) |
| 321 | if None in [drv_name, interface_id]: |
| 322 | raise ServodError('No drv/interface for control %r found' % control_name) |
Aseda Aboagye | 1d8477b | 2017-05-10 17:24:31 -0700 | [diff] [blame] | 323 | |
J. Richard Barnette | 275d9fd | 2014-02-11 14:38:54 -0800 | [diff] [blame] | 324 | if interface_id == 'servo': |
Matthew Blecker | 6b250ff | 2020-08-23 12:00:55 -0700 | [diff] [blame] | 325 | interface = weakref.proxy(self) |
Simran Basi | 668be0e | 2013-08-07 11:54:50 -0700 | [diff] [blame] | 326 | else: |
Wai-Hong Tam | 564c170 | 2017-04-24 09:23:38 -0700 | [diff] [blame] | 327 | index = int(interface_id) |
J. Richard Barnette | 275d9fd | 2014-02-11 14:38:54 -0800 | [diff] [blame] | 328 | interface = self._interface_list[index] |
Simran Basi | 668be0e | 2013-08-07 11:54:50 -0700 | [diff] [blame] | 329 | |
Mary Ruthven | 6b14d3f | 2019-07-15 12:52:53 -0700 | [diff] [blame] | 330 | device_info = None |
| 331 | if hasattr(interface, 'get_device_info'): |
| 332 | device_info = interface.get_device_info() |
Wai-Hong Tam | 4c09eff | 2017-02-17 11:46:19 -0800 | [diff] [blame] | 333 | drv_module = getattr(servo_drv, drv_name) |
Tom Wai-Hong Tam | 28f0a5f | 2012-08-21 12:49:57 +0800 | [diff] [blame] | 334 | drv_class = getattr(drv_module, self._camel_case(drv_name)) |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 335 | drv = drv_class(interface, params) |
| 336 | if control_name not in self._drv_dict: |
| 337 | self._drv_dict[control_name] = {} |
| 338 | if is_get: |
Mary Ruthven | 6b14d3f | 2019-07-15 12:52:53 -0700 | [diff] [blame] | 339 | self._drv_dict[control_name]['get'] = (params, drv, device_info) |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 340 | else: |
Mary Ruthven | 6b14d3f | 2019-07-15 12:52:53 -0700 | [diff] [blame] | 341 | self._drv_dict[control_name]['set'] = (params, drv, device_info) |
| 342 | return (params, drv, device_info) |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 343 | |
Ruben Rodriguez Buchillon | 2ffef24 | 2020-11-13 20:51:02 -0800 | [diff] [blame] | 344 | def _has_control(self, control): |
| 345 | """Returns True if control is available in servod.""" |
| 346 | return self._syscfg.is_control(control) |
| 347 | |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 348 | def doc_all(self): |
| 349 | """Return all documenation for controls. |
| 350 | |
| 351 | Returns: |
| 352 | string of <doc> text in config file (xml) and the params dictionary for |
| 353 | all controls. |
| 354 | |
| 355 | For example: |
| 356 | warm_reset :: Reset the device warmly |
| 357 | ------------------------> {'interface': '1', 'map': 'onoff_i', ... } |
| 358 | """ |
| 359 | return self._syscfg.display_config() |
| 360 | |
| 361 | def doc(self, name): |
| 362 | """Retreive doc string in system config file for given control name. |
| 363 | |
| 364 | Args: |
| 365 | name: name string of control to get doc string |
| 366 | |
| 367 | Returns: |
| 368 | doc string of name |
| 369 | |
| 370 | Raises: |
| 371 | NameError: if fails to locate control |
| 372 | """ |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 373 | self._logger.debug('name(%s)' % (name)) |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 374 | if self._syscfg.is_control(name): |
| 375 | return self._syscfg.get_control_docstring(name) |
| 376 | else: |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 377 | raise NameError('No control %s' % name) |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 378 | |
Todd Broch | 352b4b2 | 2013-03-22 09:48:40 -0700 | [diff] [blame] | 379 | def set_get_all(self, cmds): |
| 380 | """Set &| get one or more control values. |
| 381 | |
| 382 | Args: |
| 383 | cmds: list of control[:value] to get or set. |
| 384 | |
| 385 | Returns: |
| 386 | rv: list of responses from calling get or set methods. |
| 387 | """ |
| 388 | rv = [] |
| 389 | for cmd in cmds: |
| 390 | if ':' in cmd: |
Wai-Hong Tam | 269f180 | 2019-05-16 12:37:17 -0700 | [diff] [blame] | 391 | (control, value) = cmd.split(':', 1) |
Todd Broch | 352b4b2 | 2013-03-22 09:48:40 -0700 | [diff] [blame] | 392 | rv.append(self.set(control, value)) |
| 393 | else: |
| 394 | rv.append(self.get(cmd)) |
| 395 | return rv |
| 396 | |
Mary Ruthven | 493df51 | 2019-07-12 13:10:18 -0700 | [diff] [blame] | 397 | def add_serial_number(self, name, serial_number): |
| 398 | """Adds the serial number to the _serialnames dictionary. |
| 399 | |
| 400 | Args: |
| 401 | name: A string which is the key into the _serialnames dictionary. |
| 402 | serial_number: A string which is the key into the _serialnames dictionary. |
| 403 | """ |
| 404 | self._serialnames[name] = serial_number |
| 405 | self._logger.debug('Added %s %s to serialnames %r', name, serial_number, |
| 406 | self._serialnames) |
| 407 | |
Aseda Aboagye | 6921f60 | 2017-08-01 14:45:38 -0700 | [diff] [blame] | 408 | def get_serial_number(self, name): |
| 409 | """Returns the desired serial number from the serialnames dict. |
| 410 | |
| 411 | Args: |
| 412 | name: A string which is the key into the _serialnames dictionary. |
| 413 | |
| 414 | Returns: |
| 415 | A string containing the serial number or "unknown". |
| 416 | """ |
Mary Ruthven | f17fb17 | 2019-08-15 17:17:35 -0700 | [diff] [blame] | 417 | # Remove the prefix from the serialname control. Serialnames are |
| 418 | # universal. It doesn't matter what the prefix is. |
| 419 | # The prefix is separated from the main control with '.' |
| 420 | name = name.split('.', 1)[-1] |
| 421 | |
Aseda Aboagye | 6921f60 | 2017-08-01 14:45:38 -0700 | [diff] [blame] | 422 | if not name: |
| 423 | name = 'main' |
Aseda Aboagye | 6921f60 | 2017-08-01 14:45:38 -0700 | [diff] [blame] | 424 | try: |
| 425 | return self._serialnames[name] |
| 426 | except KeyError: |
| 427 | self._logger.debug("'%s_serialname' not found!", name) |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 428 | return 'unknown' |
Aseda Aboagye | 6921f60 | 2017-08-01 14:45:38 -0700 | [diff] [blame] | 429 | |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 430 | def get(self, name): |
| 431 | """Get control value. |
| 432 | |
| 433 | Args: |
| 434 | name: name string of control |
| 435 | |
| 436 | Returns: |
| 437 | Response from calling drv get method. Value is reformatted based on |
| 438 | control's dictionary parameters |
| 439 | |
| 440 | Raises: |
| 441 | HwDriverError: Error occurred while using drv |
Ruben Rodriguez Buchillon | a5d8b92 | 2018-09-03 16:51:03 +0800 | [diff] [blame] | 442 | ServodError: if interfaces are not available within timeout period |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 443 | """ |
Wai-Hong Tam | bafeca7 | 2017-10-05 14:22:12 -0700 | [diff] [blame] | 444 | if 'serialname' in name: |
Dana Goyette | 91cae86 | 2020-02-21 13:43:13 -0800 | [diff] [blame] | 445 | # This route is to retrieve serialnames on servo v4, which |
| 446 | # connects to multiple servo-micros or CCD, like the controls, |
| 447 | # 'ccd_serialname', 'servo_micro_for_soraka_serialname', etc. |
| 448 | # TODO(aaboagye): Refactor it. |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 449 | return self.get_serial_number(name.split('serialname')[0].strip('_')) |
Wai-Hong Tam | bafeca7 | 2017-10-05 14:22:12 -0700 | [diff] [blame] | 450 | |
Dana Goyette | 17b0d25 | 2020-03-09 10:32:50 -0700 | [diff] [blame] | 451 | with servo_logging.WrapGetCall( |
Dana Goyette | 4a61e90 | 2020-05-08 10:09:31 -0700 | [diff] [blame] | 452 | name, known_exceptions=self.KNOWN_EXCEPTIONS) as wrapper: |
Dana Goyette | 91cae86 | 2020-02-21 13:43:13 -0800 | [diff] [blame] | 453 | (params, drv, device) = self._get_param_drv(name) |
| 454 | if device in self._devices: |
| 455 | self._devices[device].wait(self.INTERFACE_AVAILABILITY_TIMEOUT) |
| 456 | |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 457 | val = drv.get() |
Fei Shao | 8aec57b | 2019-12-11 17:08:40 +0800 | [diff] [blame] | 458 | rd_val = self._syscfg.reformat_val(params, val) |
Dana Goyette | 91cae86 | 2020-02-21 13:43:13 -0800 | [diff] [blame] | 459 | wrapper.got_result(rd_val) |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 460 | return rd_val |
Todd Broch | d606167 | 2012-05-11 15:52:47 -0700 | [diff] [blame] | 461 | |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 462 | def get_all(self, verbose): |
| 463 | """Get all controls values. |
| 464 | |
| 465 | Args: |
| 466 | verbose: Boolean on whether to return doc info as well |
| 467 | |
| 468 | Returns: |
| 469 | string creating from trying to get all values of all controls. In case of |
| 470 | error attempting access to control, response is 'ERR'. |
| 471 | """ |
Vadim Bendebury | b07944c | 2013-01-16 10:47:10 -0800 | [diff] [blame] | 472 | rsp = [] |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 473 | for name in self._syscfg.syscfg_dict['control']: |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 474 | self._logger.debug('name = %s' % name) |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 475 | try: |
| 476 | value = self.get(name) |
| 477 | except Exception: |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 478 | value = 'ERR' |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 479 | pass |
| 480 | if verbose: |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 481 | rsp.append('GET %s = %s :: %s' % (name, value, self.doc(name))) |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 482 | else: |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 483 | rsp.append('%s:%s' % (name, value)) |
Vadim Bendebury | b07944c | 2013-01-16 10:47:10 -0800 | [diff] [blame] | 484 | return '\n'.join(sorted(rsp)) |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 485 | |
| 486 | def set(self, name, wr_val_str): |
| 487 | """Set control. |
| 488 | |
| 489 | Args: |
| 490 | name: name string of control |
| 491 | wr_val_str: value string to write. Can be integer, float or a |
| 492 | alpha-numerical that is mapped to a integer or float. |
| 493 | |
| 494 | Raises: |
| 495 | HwDriverError: Error occurred while using driver |
Ruben Rodriguez Buchillon | a5d8b92 | 2018-09-03 16:51:03 +0800 | [diff] [blame] | 496 | ServodError: if interfaces are not available within timeout period |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 497 | """ |
Dana Goyette | 17b0d25 | 2020-03-09 10:32:50 -0700 | [diff] [blame] | 498 | with servo_logging.WrapSetCall( |
Dana Goyette | 4a61e90 | 2020-05-08 10:09:31 -0700 | [diff] [blame] | 499 | name, wr_val_str, known_exceptions=self.KNOWN_EXCEPTIONS): |
Dana Goyette | 91cae86 | 2020-02-21 13:43:13 -0800 | [diff] [blame] | 500 | (params, drv, device) = self._get_param_drv(name, False) |
| 501 | if device in self._devices: |
| 502 | self._devices[device].wait(self.INTERFACE_AVAILABILITY_TIMEOUT) |
| 503 | wr_val = self._syscfg.resolve_val(params, wr_val_str) |
| 504 | |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 505 | drv.set(wr_val) |
Dana Goyette | 91cae86 | 2020-02-21 13:43:13 -0800 | [diff] [blame] | 506 | |
Ruben Rodriguez Buchillon | b5fe0f1 | 2018-05-09 10:19:56 +0800 | [diff] [blame] | 507 | # TODO(crbug.com/841097) Figure out why despite allow_none=True for both |
| 508 | # xmlrpc server & client I still have to return something to appease the |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 509 | # marshall/unmarshall |
| 510 | return True |
| 511 | |
Todd Broch | d606167 | 2012-05-11 15:52:47 -0700 | [diff] [blame] | 512 | def hwinit(self, verbose=False): |
| 513 | """Initialize all controls. |
| 514 | |
| 515 | These values are part of the system config XML files of the form |
| 516 | init=<value>. This command should be used by clients wishing to return the |
| 517 | servo and DUT its connected to a known good/safe state. |
| 518 | |
Vadim Bendebury | bb51dd4 | 2013-01-31 13:47:46 -0800 | [diff] [blame] | 519 | Note that initialization errors are ignored (as in some cases they could |
| 520 | be caused by DUT firmware deficiencies). This might need to be fine tuned |
| 521 | later. |
| 522 | |
Todd Broch | d606167 | 2012-05-11 15:52:47 -0700 | [diff] [blame] | 523 | Args: |
| 524 | verbose: boolean, if True prints info about control initialized. |
| 525 | Otherwise prints nothing. |
Vadim Bendebury | 5934e4b | 2013-02-06 13:57:54 -0800 | [diff] [blame] | 526 | |
| 527 | Returns: |
| 528 | This function is called across RPC and as such is expected to return |
| 529 | something unless transferring 'none' across is allowed. Hence adding a |
Sam Hurst | 2b48753 | 2020-08-05 11:00:23 -0700 | [diff] [blame] | 530 | mock return value to make things simpler. |
Todd Broch | d606167 | 2012-05-11 15:52:47 -0700 | [diff] [blame] | 531 | """ |
Todd Broch | d9acf0a | 2012-12-05 13:43:06 -0800 | [diff] [blame] | 532 | for control_name, value in self._syscfg.hwinit: |
Todd Broch | 3ec8df0 | 2012-11-20 10:53:03 -0800 | [diff] [blame] | 533 | try: |
John Carey | 6fe2bbf | 2015-08-31 16:13:03 -0700 | [diff] [blame] | 534 | # Workaround for bug chrome-os-partner:42349. Without this check, the |
| 535 | # gpio will briefly pulse low if we set it from high to high. |
| 536 | if self.get(control_name) != value: |
Aseda Aboagye | a849d46 | 2016-05-04 17:08:16 -0700 | [diff] [blame] | 537 | self.set(control_name, value) |
| 538 | if verbose: |
| 539 | self._logger.info('Initialized %s to %s', control_name, value) |
Ruben Rodriguez Buchillon | 70eabcc | 2019-06-20 10:23:40 -0700 | [diff] [blame] | 540 | except Exception as e: |
| 541 | self._logger.error( |
Matthew Blecker | a5d979c | 2018-10-16 20:59:19 -0700 | [diff] [blame] | 542 | 'Problem initializing %s -> %s', control_name, value) |
Ruben Rodriguez Buchillon | 70eabcc | 2019-06-20 10:23:40 -0700 | [diff] [blame] | 543 | self._logger.error(str(e)) |
| 544 | self._logger.error('Please consider verifying the logs and if the ' |
| 545 | 'error is not just a setup issue, consider filing ' |
| 546 | 'a bug. Also checkout go/servo-ki.') |
Nick Sanders | bc83628 | 2015-12-08 21:19:23 -0800 | [diff] [blame] | 547 | |
Ruben Rodriguez Buchillon | f6e72eb | 2020-09-11 17:36:19 -0700 | [diff] [blame^] | 548 | # If there is the control of 'active_dut_controller', |
| 549 | # set active_dut_controller to the default device as initialization. |
Namyoon Woo | ad2a2bb | 2019-11-04 16:26:15 -0800 | [diff] [blame] | 550 | try: |
Ruben Rodriguez Buchillon | f6e72eb | 2020-09-11 17:36:19 -0700 | [diff] [blame^] | 551 | if self._syscfg.is_control('active_dut_controller'): |
| 552 | self.set('active_dut_controller', 'default') |
Todd Broch | a10cba1 | 2019-11-25 16:00:35 -0800 | [diff] [blame] | 553 | except servo_drv.active_v4_device.activeV4DeviceError as e: |
Mary Ruthven | f547c08 | 2020-05-07 11:32:28 -0700 | [diff] [blame] | 554 | self._logger.debug('Could not set active device: %s', str(e)) |
Namyoon Woo | 6ff3661 | 2019-10-16 16:41:12 -0700 | [diff] [blame] | 555 | |
Vadim Bendebury | 5934e4b | 2013-02-06 13:57:54 -0800 | [diff] [blame] | 556 | return True |
Todd Broch | 3ec8df0 | 2012-11-20 10:53:03 -0800 | [diff] [blame] | 557 | |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 558 | def echo(self, echo): |
Sam Hurst | 2b48753 | 2020-08-05 11:00:23 -0700 | [diff] [blame] | 559 | """Mock echo function for testing/examples. |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 560 | |
| 561 | Args: |
| 562 | echo: string to echo back to client |
| 563 | """ |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 564 | self._logger.debug('echo(%s)' % (echo)) |
| 565 | return 'ECH0ING: %s' % (echo) |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 566 | |
J. Richard Barnette | e282055 | 2013-03-14 16:13:46 -0700 | [diff] [blame] | 567 | def get_board(self): |
| 568 | """Return the board specified at startup, if any.""" |
| 569 | return self._board |
| 570 | |
Wai-Hong Tam | 416cf61 | 2017-09-19 11:39:21 -0700 | [diff] [blame] | 571 | def get_base_board(self): |
| 572 | """Returns the board name of the base if present. |
| 573 | |
| 574 | Returns: |
| 575 | A string of the board name, or '' if not present. |
| 576 | """ |
| 577 | # The value is set in servo_postinit. |
| 578 | return self._base_board |
| 579 | |
Simran Basi | a23c139 | 2013-08-06 14:59:10 -0700 | [diff] [blame] | 580 | def get_version(self): |
| 581 | """Get servo board version.""" |
| 582 | return self._version |
| 583 | |
Kevin Cheng | 4b4f002 | 2016-09-09 02:37:07 -0700 | [diff] [blame] | 584 | def get_servo_serials(self): |
| 585 | """Return all the serials associated with this process.""" |
| 586 | return self._serialnames |
| 587 | |
| 588 | |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 589 | def test(): |
| 590 | """Integration testing. |
| 591 | |
| 592 | TODO(tbroch) Enhance integration test and add unittest (see mox) |
| 593 | """ |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 594 | logging.basicConfig( |
| 595 | level=logging.DEBUG, |
| 596 | format='%(asctime)s - %(name)s - ' + '%(levelname)s - %(message)s') |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 597 | # configure server & listen |
| 598 | servod_obj = Servod(1) |
Wai-Hong Tam | 564c170 | 2017-04-24 09:23:38 -0700 | [diff] [blame] | 599 | # 5 == number of interfaces on a FT4232H device |
Ruben Rodriguez Buchillon | 50f3560 | 2020-03-20 18:41:19 -0700 | [diff] [blame] | 600 | for i in range(1, 5): |
Wai-Hong Tam | 564c170 | 2017-04-24 09:23:38 -0700 | [diff] [blame] | 601 | if i == 2: |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 602 | # its an i2c interface ... see __init__ for details and TODO to make |
| 603 | # this configureable |
| 604 | servod_obj._interface_list[i].wr_rd(0x21, [0], 1) |
| 605 | else: |
| 606 | # its a gpio interface |
| 607 | servod_obj._interface_list[i].wr_rd(0) |
| 608 | |
Ruben Rodriguez Buchillon | 529b0de | 2020-03-20 18:33:36 -0700 | [diff] [blame] | 609 | server = SimpleXMLRPCServer(('localhost', 9999), allow_none=True) |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 610 | server.register_introspection_functions() |
| 611 | server.register_multicall_functions() |
| 612 | server.register_instance(servod_obj) |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 613 | logging.info('Listening on localhost port 9999') |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 614 | server.serve_forever() |
| 615 | |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 616 | |
| 617 | if __name__ == '__main__': |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 618 | test() |
| 619 | |
| 620 | # simple client transaction would look like |
Puthikorn Voravootivat | 01ead15 | 2018-03-23 15:38:40 -0700 | [diff] [blame] | 621 | """remote_uri = 'http://localhost:9999' client = xmlrpclib.ServerProxy(remote_uri, verbose=False) send_str = "Hello_there" print "Sent " + send_str + ", Recv " + client.echo(send_str) |
| 622 | |
Todd Broch | e505b8d | 2011-03-21 18:19:54 -0700 | [diff] [blame] | 623 | """ |