1 |
#!/usr/bin/python |
---|
2 |
# |
---|
3 |
# Copyright (C) 2005-2007 by Pieter Palmers |
---|
4 |
# 2007-2008 by Arnold Krille |
---|
5 |
# |
---|
6 |
# This file is part of FFADO |
---|
7 |
# FFADO = Free FireWire (pro-)audio drivers for Linux |
---|
8 |
# |
---|
9 |
# FFADO is based upon FreeBoB. |
---|
10 |
# |
---|
11 |
# This program is free software: you can redistribute it and/or modify |
---|
12 |
# it under the terms of the GNU General Public License as published by |
---|
13 |
# the Free Software Foundation, either version 3 of the License, or |
---|
14 |
# (at your option) any later version. |
---|
15 |
# |
---|
16 |
# This program is distributed in the hope that it will be useful, |
---|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 |
# GNU General Public License for more details. |
---|
20 |
# |
---|
21 |
# You should have received a copy of the GNU General Public License |
---|
22 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
23 |
# |
---|
24 |
|
---|
25 |
import sys |
---|
26 |
|
---|
27 |
import os |
---|
28 |
import time |
---|
29 |
import dbus |
---|
30 |
|
---|
31 |
class ControlInterface: |
---|
32 |
def __init__(self, servername, basepath): |
---|
33 |
self.basepath=basepath |
---|
34 |
self.servername=servername |
---|
35 |
self.bus=dbus.SessionBus() |
---|
36 |
|
---|
37 |
def setContignuous(self, subpath, v, idx=None): |
---|
38 |
try: |
---|
39 |
path = self.basepath + subpath |
---|
40 |
dev = self.bus.get_object(self.servername, path) |
---|
41 |
dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Continuous') |
---|
42 |
if idx == None: |
---|
43 |
dev_cont.setValue(v) |
---|
44 |
else: |
---|
45 |
dev_cont.setValueIdx(idx,v) |
---|
46 |
except: |
---|
47 |
print( "Failed to set Continuous %s on server %s" % (path, self.servername) ) |
---|
48 |
|
---|
49 |
def getContignuous(self, subpath, idx=None): |
---|
50 |
try: |
---|
51 |
path = self.basepath + subpath |
---|
52 |
dev = self.bus.get_object(self.servername, path) |
---|
53 |
dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Continuous') |
---|
54 |
if idx == None: |
---|
55 |
return dev_cont.getValue() |
---|
56 |
else: |
---|
57 |
return dev_cont.getValueIdx(idx) |
---|
58 |
except: |
---|
59 |
print( "Failed to get Continuous %s on server %s" % (path, self.servername) ) |
---|
60 |
return 0 |
---|
61 |
|
---|
62 |
def setDiscrete(self, subpath, v): |
---|
63 |
try: |
---|
64 |
path = self.basepath + subpath |
---|
65 |
dev = self.bus.get_object(self.servername, path) |
---|
66 |
dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Discrete') |
---|
67 |
dev_cont.setValue(v) |
---|
68 |
except: |
---|
69 |
print( "Failed to set Discrete %s on server %s" % (path, self.servername) ) |
---|
70 |
|
---|
71 |
def getDiscrete(self, subpath): |
---|
72 |
try: |
---|
73 |
path = self.basepath + subpath |
---|
74 |
dev = self.bus.get_object(self.servername, path) |
---|
75 |
dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Discrete') |
---|
76 |
return dev_cont.getValue() |
---|
77 |
except: |
---|
78 |
print( "Failed to get Discrete %s on server %s" % (path, self.servername) ) |
---|
79 |
return 0 |
---|
80 |
|
---|
81 |
def setRegister(self, subpath, address, value): |
---|
82 |
try: |
---|
83 |
path = self.basepath + subpath |
---|
84 |
dev = self.bus.get_object(self.servername, path) |
---|
85 |
dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Register') |
---|
86 |
dev_cont.setValue(address, value) |
---|
87 |
except: |
---|
88 |
print( "Failed to set Register %s on server %s" % (path, self.servername) ) |
---|
89 |
|
---|
90 |
def getRegister(self, subpath, address): |
---|
91 |
try: |
---|
92 |
path = self.basepath + subpath |
---|
93 |
dev = self.bus.get_object(self.servername, path) |
---|
94 |
dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Register') |
---|
95 |
return dev_cont.getValue(address) |
---|
96 |
except: |
---|
97 |
print( "Failed to get Register %s on server %s" % (path, self.servername) ) |
---|
98 |
return 0 |
---|
99 |
|
---|
100 |
def setText(self, subpath, v): |
---|
101 |
try: |
---|
102 |
path = self.basepath + subpath |
---|
103 |
dev = self.bus.get_object(self.servername, path) |
---|
104 |
dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Text') |
---|
105 |
dev_cont.setValue(v) |
---|
106 |
except: |
---|
107 |
print( "Failed to set Text %s on server %s" % (path, self.servername) ) |
---|
108 |
|
---|
109 |
def getText(self, subpath): |
---|
110 |
try: |
---|
111 |
path = self.basepath + subpath |
---|
112 |
dev = self.bus.get_object(self.servername, path) |
---|
113 |
dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Text') |
---|
114 |
return dev_cont.getValue() |
---|
115 |
except: |
---|
116 |
print( "Failed to get Text %s on server %s" % (path, self.servername) ) |
---|
117 |
return 0 |
---|
118 |
|
---|
119 |
def setMatrixMixerValue(self, subpath, row, col, v): |
---|
120 |
try: |
---|
121 |
path = self.basepath + subpath |
---|
122 |
dev = self.bus.get_object(self.servername, path) |
---|
123 |
dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.MatrixMixer') |
---|
124 |
dev_cont.setValue(row, col, v) |
---|
125 |
except: |
---|
126 |
print( "Failed to set MatrixMixer %s on server %s" % (path, self.servername) ) |
---|
127 |
|
---|
128 |
def getMatrixMixerValue(self, subpath, row, col): |
---|
129 |
try: |
---|
130 |
path = self.basepath + subpath |
---|
131 |
dev = self.bus.get_object(self.servername, path) |
---|
132 |
dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.MatrixMixer') |
---|
133 |
return dev_cont.getValue(row, col) |
---|
134 |
except: |
---|
135 |
print( "Failed to get MatrixMixer %s on server %s" % (path, self.servername) ) |
---|
136 |
return 0 |
---|
137 |
|
---|
138 |
def enumSelect(self, subpath, v): |
---|
139 |
try: |
---|
140 |
path = self.basepath + subpath |
---|
141 |
dev = self.bus.get_object(self.servername, path) |
---|
142 |
dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Enum') |
---|
143 |
dev_cont.select(v) |
---|
144 |
except: |
---|
145 |
print( "Failed to select %s on server %s" % (path, self.servername) ) |
---|
146 |
|
---|
147 |
def enumSelected(self, subpath): |
---|
148 |
try: |
---|
149 |
path = self.basepath + subpath |
---|
150 |
dev = self.bus.get_object(self.servername, path) |
---|
151 |
dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Enum') |
---|
152 |
return dev_cont.selected() |
---|
153 |
except: |
---|
154 |
print( "Failed to get selected enum %s on server %s" % (path, self.servername) ) |
---|
155 |
return 0 |
---|
156 |
|
---|
157 |
def enumGetLabel(self, subpath, v): |
---|
158 |
try: |
---|
159 |
path = self.basepath + subpath |
---|
160 |
dev = self.bus.get_object(self.servername, path) |
---|
161 |
dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Enum') |
---|
162 |
return dev_cont.getEnumLabel(v) |
---|
163 |
except: |
---|
164 |
print( "Failed to get enum label %s on server %s" % (path, self.servername) ) |
---|
165 |
return 0 |
---|
166 |
|
---|
167 |
def enumCount(self, subpath): |
---|
168 |
try: |
---|
169 |
path = self.basepath + subpath |
---|
170 |
dev = self.bus.get_object(self.servername, path) |
---|
171 |
dev_cont = dbus.Interface(dev, dbus_interface='org.ffado.Control.Element.Enum') |
---|
172 |
return dev_cont.count() |
---|
173 |
except: |
---|
174 |
print( "Failed to get enum count %s on server %s" % (path, self.servername) ) |
---|
175 |
return 0 |
---|
176 |
|
---|
177 |
class DeviceManagerInterface: |
---|
178 |
def __init__(self, servername, basepath): |
---|
179 |
self.basepath=basepath + '/DeviceManager' |
---|
180 |
self.servername=servername |
---|
181 |
self.bus=dbus.SessionBus() |
---|
182 |
self.dev = self.bus.get_object(self.servername, self.basepath) |
---|
183 |
self.iface = dbus.Interface(self.dev, dbus_interface='org.ffado.Control.Element.Container') |
---|
184 |
# signal reception does not work yet since we need a mainloop for that |
---|
185 |
# and qt3 doesn't provide one for python/dbus |
---|
186 |
#try: |
---|
187 |
#self.dev.connect_to_signal("Updated", self.updateSignal, \ |
---|
188 |
#dbus_interface="org.ffado.Control.Element.Container", arg0=self) |
---|
189 |
#except dbus.DBusException: |
---|
190 |
#traceback.print_exc() |
---|
191 |
|
---|
192 |
#def updateSignal(self): |
---|
193 |
#print( ("Received update signal") ) |
---|
194 |
|
---|
195 |
def getNbDevices(self): |
---|
196 |
return self.iface.getNbElements() |
---|
197 |
def getDeviceName(self, idx): |
---|
198 |
return self.iface.getElementName(idx) |
---|
199 |
|
---|
200 |
|
---|
201 |
class ConfigRomInterface: |
---|
202 |
def __init__(self, servername, devicepath): |
---|
203 |
self.basepath=devicepath + '/ConfigRom' |
---|
204 |
self.servername=servername |
---|
205 |
self.bus=dbus.SessionBus() |
---|
206 |
self.dev = self.bus.get_object(self.servername, self.basepath) |
---|
207 |
self.iface = dbus.Interface(self.dev, dbus_interface='org.ffado.Control.Element.ConfigRomX') |
---|
208 |
def getGUID(self): |
---|
209 |
return self.iface.getGUID() |
---|
210 |
def getVendorName(self): |
---|
211 |
return self.iface.getVendorName() |
---|
212 |
def getModelName(self): |
---|
213 |
return self.iface.getModelName() |
---|
214 |
def getVendorId(self): |
---|
215 |
return self.iface.getVendorId() |
---|
216 |
def getModelId(self): |
---|
217 |
return self.iface.getModelId() |
---|
218 |
def getUnitVersion(self): |
---|
219 |
return self.iface.getUnitVersion() |
---|
220 |
|
---|
221 |
class ClockSelectInterface: |
---|
222 |
def __init__(self, servername, devicepath): |
---|
223 |
self.basepath=devicepath + '/Generic/ClockSelect' |
---|
224 |
self.servername=servername |
---|
225 |
self.bus=dbus.SessionBus() |
---|
226 |
self.dev = self.bus.get_object(self.servername, self.basepath) |
---|
227 |
self.iface = dbus.Interface(self.dev, dbus_interface='org.ffado.Control.Element.AttributeEnum') |
---|
228 |
def count(self): |
---|
229 |
return self.iface.count() |
---|
230 |
def select(self, idx): |
---|
231 |
return self.iface.select(idx) |
---|
232 |
def selected(self): |
---|
233 |
return self.iface.selected() |
---|
234 |
def getEnumLabel(self, idx): |
---|
235 |
return self.iface.getEnumLabel(idx) |
---|
236 |
def attributeCount(self): |
---|
237 |
return self.iface.attributeCount() |
---|
238 |
def getAttributeValue(self, idx): |
---|
239 |
return self.iface.getAttributeValue(idx) |
---|
240 |
def getAttributeName(self, idx): |
---|
241 |
return self.iface.getAttributeName(idx) |
---|
242 |
|
---|
243 |
class TextInterface: |
---|
244 |
def __init__(self, servername, basepath): |
---|
245 |
self.basepath=basepath |
---|
246 |
self.servername=servername |
---|
247 |
self.bus=dbus.SessionBus() |
---|
248 |
self.dev = self.bus.get_object( self.servername, self.basepath ) |
---|
249 |
self.iface = dbus.Interface( self.dev, dbus_interface="org.ffado.Control.Element.Text" ) |
---|
250 |
|
---|
251 |
def text(self): |
---|
252 |
return self.iface.getValue() |
---|
253 |
|
---|
254 |
def setText(self,text): |
---|
255 |
self.iface.setValue(text) |
---|
256 |
|
---|
257 |
if __name__ == "__main__": |
---|
258 |
|
---|
259 |
print( """ ) |
---|
260 |
=========================================================== |
---|
261 |
FFADO DBUS TEST TOOL |
---|
262 |
=========================================================== |
---|
263 |
""" |
---|
264 |
|
---|
265 |
server='org.ffado.Control' |
---|
266 |
basepath='/org/ffado/Control' |
---|
267 |
|
---|
268 |
repeat = 1 |
---|
269 |
while repeat > 0: |
---|
270 |
try: |
---|
271 |
devmgr = DeviceManagerInterface(server, basepath) |
---|
272 |
nbDevices = devmgr.getNbDevices() |
---|
273 |
repeat -= 1 |
---|
274 |
except dbus.DBusException, ex: |
---|
275 |
print( "\n" ) |
---|
276 |
print( "===========================================================" ) |
---|
277 |
print( "ERROR: Could not communicate with the FFADO DBus service..." ) |
---|
278 |
print( "===========================================================" ) |
---|
279 |
print( "\n" ) |
---|
280 |
sys.exit( -1 ) |
---|
281 |
|
---|
282 |
if nbDevices == 0: |
---|
283 |
print( "No supported device found..." ) |
---|
284 |
sys.exit( -1 ) |
---|
285 |
|
---|
286 |
idx = 0 |
---|
287 |
|
---|
288 |
path=devmgr.getDeviceName(idx) |
---|
289 |
print( "Found device %d: %s" % (idx, path) ) |
---|
290 |
|
---|
291 |
cfgrom = ConfigRomInterface(server, basepath+'/DeviceManager/'+path) |
---|
292 |
vendorId = cfgrom.getVendorId() |
---|
293 |
modelId = cfgrom.getModelId() |
---|
294 |
unitVersion = cfgrom.getUnitVersion() |
---|
295 |
GUID = cfgrom.getGUID() |
---|
296 |
vendorName = cfgrom.getVendorName() |
---|
297 |
modelName = cfgrom.getModelName() |
---|
298 |
print( " Found (%s, %X, %X) %s %s" % (str(GUID), vendorId, modelId, vendorName, modelName) ) |
---|
299 |
|
---|
300 |
# create a control objects |
---|
301 |
hw = ControlInterface(server, basepath+'/DeviceManager/'+path) |
---|
302 |
clockselect = ClockSelectInterface( server, basepath+"/DeviceManager/"+path ) |
---|
303 |
nickname = TextInterface( server, basepath+"/DeviceManager/"+path+"/Generic/Nickname" ) |
---|
304 |
|
---|
305 |
import time |
---|
306 |
register = range(60) |
---|
307 |
# do whatever you have to do |
---|
308 |
for i in range(60): |
---|
309 |
for regid in range(60): |
---|
310 |
newval = hw.getRegister("/Register", regid) |
---|
311 |
oldval = register[regid] |
---|
312 |
if newval != oldval: |
---|
313 |
print( "%04d: from %8d | %08X to %8d | %08X" % (regid, oldval, oldval, newval, newval) ) |
---|
314 |
register[regid] = newval |
---|
315 |
time.sleep(0.2) |
---|
316 |
print( "--- %d ---" % i ) |
---|
317 |
#time.sleep(1) |
---|
318 |
|
---|
319 |
#regid=eval(sys.argv[1]) |
---|
320 |
#val=eval(sys.argv[2]) |
---|
321 |
#print( hw.getRegister("/Register", regid) ) |
---|
322 |
#hw.setRegister("/Register", regid, val) |
---|
323 |
|
---|