Debian Codegraph @

examples/usbpower/README.rst

raw
1 USB Power and SD-Mux Example
2 ============================
3
4 Files
5 -----
6
7 cycle.py
8 Python script which uses labgrid as a library and directly cycles power on
9 the USBPowerPort.
10
11 local.yaml
12 Environment configuration to use USBPowerPort, USBSerialPort and
13 USBSDMuxDevice resources which are connected locally.
14
15 examplestrategy.py
16 Custom strategy which controls the USB-SD-Mux and the USB port power.
17
18 test_example.py
19 Testsuite (based on pytest) to run a simple command in barebox, shell and
20 barebox again.
21
22 exports.yaml
23 Configuration file for labgrid-exporter to export these resources over the
24 network.
25
26 remote.yaml
27 Environment configuration to use USBPowerPort, USBSerialPort and
28 USBSDMuxDevice resources which are connected remotely (to the place 'demo1').
29
30 Hardware Setup
31 --------------
32
33 This example uses a USB hub which has power control (as supported by `uhubctl
34 <https://github.com/mvp/uhubctl>`_), a USB serial converter, a `USB-SD-Mux
35 <https://www.pengutronix.de/de/2017-10-23-usb-sd-mux-automated-sd-card-juggler.html>
36 board`_ and a USB powered target.
37 The target is connected on port 1, the serial converer on port2 and the SD-Mux
38 on port 3.
39
40 Software Setup
41 --------------
42
43 The ``uhubctl`` and ``usbsdmux`` tools need to be installed on the system.
44
45 Library Example
46 ---------------
47
48 Ensure that the hardware is connected and run ``python cycle.py``.
49 You should get the following output::
50
51 Target: Target(name='main', env=None)
52 Resources: [USBPowerPort(target=Target(name='main', env=None), name=None, state=<BindingState.active: 2>, avail=True, timeout=5.0, match={'SUBSYSTEM': 'usb', 'DEVTYPE': 'usb_interface', 'ID_PATH': 'pci-0000:00:14.0-usb-0:2:1.0', 'DRIVER': 'hub'}, device=Device('/sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0'), index=1)]
53 Drivers: [USBPowerDriver(target=Target(name='main', env=None), name=None, state=<BindingState.active: 2>, delay=2.0)]
54 Status: True
55
56 === Switching power OFF ===
57 Current status for hub 1-2 [05e3:0608 USB2.0 Hub, USB 2.10, 4 ports]
58 Port 1: 0100 power
59 Sent power off request
60 New status for hub 1-2 [05e3:0608 USB2.0 Hub, USB 2.10, 4 ports]
61 Port 1: 0000 off
62 Status: False
63
64 === Switching power ON ===
65 Current status for hub 1-2 [05e3:0608 USB2.0 Hub, USB 2.10, 4 ports]
66 Port 1: 0000 off
67 Sent power on request
68 New status for hub 1-2 [05e3:0608 USB2.0 Hub, USB 2.10, 4 ports]
69 Port 1: 0100 power
70 Status: True
71
72 Local pytest Example
73 --------------------
74
75 Run ``pytest --lg-env local.yaml -v``.
76 You should get output similar to the following::
77
78 ========================================== test session starts ===========================================
79 platform linux -- Python 3.5.3, pytest-3.4.0, py-1.5.2, pluggy-0.6.0 -- /home/jluebbe/ptx/labgrid/venv/bin/python3
80 cachedir: ../.pytest_cache
81 rootdir: /home/jluebbe/ptx/labgrid/examples, inifile: pytest.ini
82 plugins: pylint-0.7.1, mock-1.6.3, isort-0.1.0, cov-2.5.1, labgrid-0.1.1.dev242+ge3d60c7
83 collected 3 items
84 test_example.py::test_barebox
85 Current status for hub 1-2 [05e3:0608 USB2.0 Hub, USB 2.10, 4 ports]
86 Port 1: 0100 power
87 Sent power off request
88 New status for hub 1-2 [05e3:0608 USB2.0 Hub, USB 2.10, 4 ports]
89 Port 1: 0000 off
90 Current status for hub 1-2 [05e3:0608 USB2.0 Hub, USB 2.10, 4 ports]
91 Port 1: 0000 off
92 Sent power on request
93 New status for hub 1-2 [05e3:0608 USB2.0 Hub, USB 2.10, 4 ports]
94 Port 1: 0100 power
95 PASSED [ 33%]
96 test_example.py::test_shell
97 PASSED [ 66%]
98 test_example.py::test_barebox_2
99 Current status for hub 1-2 [05e3:0608 USB2.0 Hub, USB 2.10, 4 ports]
100 Port 1: 0100 power
101 Sent power off request
102 New status for hub 1-2 [05e3:0608 USB2.0 Hub, USB 2.10, 4 ports]
103 Port 1: 0000 off
104 Current status for hub 1-2 [05e3:0608 USB2.0 Hub, USB 2.10, 4 ports]
105 Port 1: 0000 off
106 Sent power on request
107 New status for hub 1-2 [05e3:0608 USB2.0 Hub, USB 2.10, 4 ports]
108 Port 1: 0100 power
109 PASSED [100%]
110
111 ======================================= 3 passed in 23.90 seconds ========================================
112
113 Remote Setup
114 ------------
115
116 To access resources remotely, you first need to start the coordinator::
117 $ labgrid-coordinator
118 [...]
119 Coordinator ready
120
121 Then, you need to start the exporter::
122 $ labgrid-exporter exports.yaml
123 [...]
124
125 Now, you can use ``labgrid-client`` to show resources and configure a place::
126 $ labgrid-client resources
127 polaris/hub-p1/NetworkUSBPowerPort
128 polaris/hub-p2/NetworkUSBPowerPort
129 polaris/hub-p2/NetworkSerialPort
130 polaris/hub-p3/NetworkUSBPowerPort
131 polaris/hub-p3/NetworkUSBSDMuxDevice
132 polaris/hub-p4/NetworkUSBPowerPort
133 $ labgrid-client -p demo1 create
134 $ labgrid-client -p demo1 add-match polaris/hub-p1/NetworkUSBPowerPort
135 $ labgrid-client -p demo1 add-match polaris/hub-p2/NetworkSerialPort
136 $ labgrid-client -p demo1 add-match polaris/hub-p3/NetworkUSBSDMuxDevice
137 $ labgrid-client places
138 demo1
139 $ labgrid-client -p demo1 lock
140 acquired place demo1
141 $ labgrid-client -p demo1 show
142 Place 'demo1':
143 aliases:
144 comment:
145 matches:
146 polaris/hub-p1/NetworkUSBPowerPort
147 polaris/hub-p2/NetworkSerialPort
148 polaris/hub-p3/NetworkUSBSDMuxDevice
149 acquired: polaris/jluebbe
150 acquired resources:
151 polaris/hub-p1/NetworkUSBPowerPort/USBPowerPort
152 polaris/hub-p2/NetworkSerialPort/USBSerialPort
153 polaris/hub-p3/NetworkUSBSDMuxDevice/USBSDMuxDevice
154 created: 2018-03-20 10:41:07.561995
155 changed: 2018-03-20 15:48:25.928298
156 Acquired resource 'USBPowerPort' (polaris/hub-p1/NetworkUSBPowerPort/USBPowerPort):
157 {'acquired': None,
158 'avail': True,
159 'cls': 'NetworkUSBPowerPort',
160 'params': {'busnum': 1,
161 'devnum': 95,
162 'host': 'polaris',
163 'index': 1,
164 'model_id': 1544,
165 'path': '1-2',
166 'vendor_id': 1507}}
167 Acquired resource 'USBSerialPort' (polaris/hub-p2/NetworkSerialPort/USBSerialPort):
168 {'acquired': None,
169 'avail': True,
170 'cls': 'NetworkSerialPort',
171 'params': {'extra': {'path': '/dev/ttyUSB0'},
172 'host': 'polaris',
173 'port': 52363}}
174 Acquired resource 'USBSDMuxDevice' (polaris/hub-p3/NetworkUSBSDMuxDevice/USBSDMuxDevice):
175 {'acquired': None,
176 'avail': True,
177 'cls': 'NetworkUSBSDMuxDevice',
178 'params': {'busnum': 1,
179 'control_path': '/dev/sg1',
180 'devnum': 98,
181 'host': 'polaris',
182 'model_id': 16449,
183 'path': '/dev/sdb',
184 'vendor_id': 1060}}
185 $ labgrid-client who
186 User Host Place Changed
187 jluebbe polaris demo1 2018-03-20 15:50:18.413377
188 $ labgrid-client -p demo1 sd-mux dut
189 Success
190 $ labgrid-client -p demo1 power cycle
191 Current status for hub 1-2 [05e3:0608 USB2.0 Hub, USB 2.10, 4 ports]
192 Port 1: 0100 power
193 Sent power off request
194 New status for hub 1-2 [05e3:0608 USB2.0 Hub, USB 2.10, 4 ports]
195 Port 1: 0000 off
196 Current status for hub 1-2 [05e3:0608 USB2.0 Hub, USB 2.10, 4 ports]
197 Port 1: 0000 off
198 Sent power on request
199 New status for hub 1-2 [05e3:0608 USB2.0 Hub, USB 2.10, 4 ports]
200 Port 1: 0100 power
201 $ labgrid-client -p demo1 console
202 connecting to NetworkSerialPort(target=Target(name='demo1', env=None), name='USBSerialPort', state=<BindingState.bound: 1>, avail=True, host='polaris', port=52363, speed=115200, protocol='rfc2217') calling microcom -s 115200 -t polaris:52363
203 connected to 127.0.1.1 (port 52363)
204 Escape character: Ctrl-\
205 Type the escape character followed by c to get to the menu or q to quit
206
207
208 barebox 2018.03.0-20180308-1 #1 Thu Mar 8 17:11:54 CET 2018
209
210
211 Board: RaspberryPi 3 Model B
212 bcm2835_mci 3f300000.sdhci: registered as 3f300000.sdhci
213 bcm2835-gpio 3f200000.gpio: probed gpiochip-1 with base 0
214 pitft@0-2: setting up native-CS0 as GPIO 8
215 fbtft_of_value: buswidth = 8
216 fbtft_of_value: debug = 4294967295
217 fbtft_of_value: rotate = 0
218 fbtft_of_value: fps = 25
219 mci0: detected SD card version 2.0
220 mci0: registered disk0
221 state: New state registered 'state'
222 state: Using bucket 0@0x00000000
223 malloc space: 0x0fefe3c0 -> 0x1fdfc77f (size 255 MiB)
224 bcm2835_fb bcm2835_fb0: registered
225
226 Hit any key to stop autoboot:
227 barebox@RaspberryPi 3 Model B:/
228
229 Remote pytest Example
230 ---------------------
231
232 Run ``pytest --lg-env remote.yaml -v``.
233
234 You should get output very similar to the local pytest example above.