def getCurrentTsidOnid(self, from_retune = False): self.currentProcess = currentProcess = datetime.datetime.now() self["tsid"].setText("") self["onid"].setText("") self["pos"].setText("") #(self.DVB_type.value) self["key_yellow"].setText("") self["actions2"].setEnabled(False) self.serviceList = [] if not dvbreader_available or self.frontend is None or self.demux < 0: return if from_retune: # give the tuner a chance to retune or we will be reading the old stream time.sleep(1.0) if not self.tunerLock() and not self.waitTunerLock(currentProcess): # dont even try to read the transport stream if tuner is not locked return thread.start_new_thread(self.monitorTunerLock, (currentProcess,)) # if tuner loses lock we start again from scratch adapter = 0 demuxer_device = "/dev/dvb/adapter%d/demux%d" % (adapter, self.demux) sdt_pid = 0x11 sdt_current_table_id = 0x42 mask = 0xff tsidOnidTimeout = 60 # maximum time allowed to read the service descriptor table (seconds) self.tsid = None self.onid = None sdt_current_version_number = -1 sdt_current_sections_read = [] sdt_current_sections_count = 0 sdt_current_content = [] sdt_current_completed = False fd = dvbreader.open(demuxer_device, sdt_pid, sdt_current_table_id, mask, self.feid) if fd < 0: print "[Satfinder][getCurrentTsidOnid] Cannot open the demuxer" return None timeout = datetime.datetime.now() timeout += datetime.timedelta(0, tsidOnidTimeout) while True: if datetime.datetime.now() > timeout: print "[Satfinder][getCurrentTsidOnid] Timed out" break if self.currentProcess != currentProcess or not self.tunerLock(): dvbreader.close(fd) return section = dvbreader.read_sdt(fd, sdt_current_table_id, 0x00) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"]["table_id"] == sdt_current_table_id and not sdt_current_completed: if section["header"]["version_number"] != sdt_current_version_number: sdt_current_version_number = section["header"]["version_number"] sdt_current_sections_read = [] sdt_current_sections_count = section["header"]["last_section_number"] + 1 sdt_current_content = [] if section["header"]["section_number"] not in sdt_current_sections_read: sdt_current_sections_read.append(section["header"]["section_number"]) sdt_current_content += section["content"] if self.tsid is None or self.onid is None: # write first find straight to the screen self.tsid = section["header"]["transport_stream_id"] self.onid = section["header"]["original_network_id"] self["tsid"].setText("%d" % (section["header"]["transport_stream_id"])) self["onid"].setText("%d" % (section["header"]["original_network_id"])) print "[Satfinder][getCurrentTsidOnid] tsid %d, onid %d" % (section["header"]["transport_stream_id"], section["header"]["original_network_id"]) if len(sdt_current_sections_read) == sdt_current_sections_count: sdt_current_completed = True if sdt_current_completed: break dvbreader.close(fd) if not sdt_current_content: print "[Satfinder][getCurrentTsidOnid] no services found on transponder" return for i in range(len(sdt_current_content)): if not sdt_current_content[i]["service_name"]: # if service name is empty use SID sdt_current_content[i]["service_name"] = "0x%x" % sdt_current_content[i]["service_id"] self.serviceList = sorted(sdt_current_content, key=lambda listItem: listItem["service_name"]) if self.serviceList: self["key_yellow"].setText(_("Service list")) self["actions2"].setEnabled(True) self.getOrbPosFromNit(currentProcess)
def getCurrentTsidOnid(self, currentProcess): self.serviceList = [] if not dvbreader_available or self.frontend is None: return adapter = 0 demuxer_device = "/dev/dvb/adapter%d/demux%d" % (adapter, self.demux) sdt_pid = 0x11 sdt_current_table_id = 0x42 mask = 0xff tsidOnidTimeout = 60 self.tsid = None self.onid = None sdt_current_version_number = -1 sdt_current_sections_read = [] sdt_current_sections_count = 0 sdt_current_content = [] sdt_current_completed = False fd = dvbreader.open(demuxer_device, sdt_pid, sdt_current_table_id, mask, self.feid) if fd < 0: print "[Satfinder][getCurrentTsidOnid] Cannot open the demuxer" return None timeout = datetime.datetime.now() timeout += datetime.timedelta(0, tsidOnidTimeout) while True: if datetime.datetime.now() > timeout: print "[Satfinder][getCurrentTsidOnid] Timed out" break if self.currentProcess != currentProcess: dvbreader.close(fd) print "[satfinder][getCurrentTsidOnid] killed: %s, currentProcess: %s" % ( currentProcess, self.currentProcess) return section = dvbreader.read_sdt(fd, sdt_current_table_id, 0x00) if section is None: time.sleep(0.1) # no data.. so we wait a bit continue if section["header"][ "table_id"] == sdt_current_table_id and not sdt_current_completed: if section["header"][ "version_number"] != sdt_current_version_number: sdt_current_version_number = section["header"][ "version_number"] sdt_current_sections_read = [] sdt_current_sections_count = section["header"][ "last_section_number"] + 1 sdt_current_content = [] if section["header"][ "section_number"] not in sdt_current_sections_read: sdt_current_sections_read.append( section["header"]["section_number"]) sdt_current_content += section["content"] if self.tsid is None or self.onid is None: # write first find straight to the screen self.tsid = section["header"]["transport_stream_id"] self.onid = section["header"]["original_network_id"] self["tsid"].setText( "%d" % (section["header"]["transport_stream_id"])) self["onid"].setText( "%d" % (section["header"]["original_network_id"])) #self["introduction"].setText("TSID: %d, ONID: %d" % (section["header"]["transport_stream_id"], section["header"]["original_network_id")) print "[Satfinder][getCurrentTsidOnid] tsid %d, onid %d" % ( section["header"]["transport_stream_id"], section["header"]["original_network_id"]) if len(sdt_current_sections_read ) == sdt_current_sections_count: sdt_current_completed = True if sdt_current_completed: break dvbreader.close(fd) if not sdt_current_content: print "[Satfinder][keyReadServices] no services found on transponder" return for i in range(len(sdt_current_content)): if not sdt_current_content[i][ "service_name"]: # if service name is empty use SID sdt_current_content[i][ "service_name"] = "0x%x" % sdt_current_content[i][ "service_id"] self.serviceList = sorted( sdt_current_content, key=lambda listItem: listItem["service_name"]) if self.serviceList: self["key_yellow"].setText(_("Service list")) try: self.getOrbPosFromNit(currentProcess) if self.orb_pos: self["pos"].setText(_("%s") % self.orb_pos) #self["introduction"].setText("TSID: %d, ONID: %d, %s" % (self.tsid, self.onid, self.orb_pos)) except Exception, e: print "[satfinder][getCurrentTsidOnid] exception", e