from struct import Struct from array import array import fcntl import ioctls DTV_UNDEFINED = 0 DTV_TUNE = 1 DTV_CLEAR = 2 DTV_FREQUENCY = 3 DTV_MODULATION = 4 DTV_BANDWIDTH_HZ = 5 DTV_INVERSION = 6 DTV_DISEQC_MASTER = 7 DTV_SYMBOL_RATE = 8 DTV_INNER_FEC = 9 DTV_VOLTAGE = 10 DTV_TONE = 11 DTV_PILOT = 12 DTV_ROLLOFF = 13 DTV_DISEQC_SLAVE_REPLY = 14 DTV_FE_CAPABILITY_COUNT = 15 DTV_FE_CAPABILITY = 16 DTV_DELIVERY_SYSTEM = 17 DTV_API_VERSION = 35 DTV_API_VERSION = 35 DTV_CODE_RATE_HP = 36 DTV_CODE_RATE_LP = 37 DTV_GUARD_INTERVAL = 38 DTV_TRANSMISSION_MODE = 39 DTV_HIERARCHY = 40 DTV_MAX_COMMAND = 40 dtv_properties = Struct("IP") dtv_property_u32 = Struct("I12xI44xPI") # The P is unused, but we need it here because we don't know the # size of void* dtv_property_buffer = Struct("I12x32BI12xPI") dvb_frontend_event = Struct("I32x") dmx_pes_filter = Struct("HIIII") def cvt32(i): return int(-(i ^ 0xffffffff)-1) class Property(object): def __init__(self, type=DTV_UNDEFINED, value=0, buf=None): if buf == None: self.type = type self.value = value else: res = dtv_property_u32.unpack(buf) self.type = res[0] self.value = res[1] self.result = res[3] def __iter__(self): arr = dtv_property_u32.pack(self.type, self.value, 0, 0) return iter(arr) class Properties(list): def _properties(self, f, ioctl): # Construct an array of the things we want to know buf = array('c') for p in self: buf.extend(p) # Get its address rladdr, rllen = buf.buffer_info() # Create the header to pass to the ioctl head = dtv_properties.pack(len(self), rladdr) fcntl.ioctl(f, cvt32(ioctl), head) # Read the data back into the array stride = dtv_property_u32.size for i in range(0, len(self)): pos = i*stride self[i] = Property(buf=buf[pos:pos+stride]) def get_properties(self, f): self._properties(f, ioctls.FE_GET_PROPERTY) def set_properties(self, f): self._properties(f, ioctls.FE_SET_PROPERTY)