Пример #1
0
    def main(self):
        while not self.shutdown():

            while self.dataReady("inbox"):
                data = self.recv("inbox")

                # extract basic info from this PSI packet - enough to work
                # out what table it is; what section, and the version
                e = [ord(data[i]) for i in range(0, 3)]

                table_id = e[0]
                if table_id != 0x73:
                    continue

                syntax = e[1] & 0x80
                if syntax:
                    continue

                section_length = ((e[1] << 8) + e[2]) & 0x0fff

                if not dvbcrc(data[:3 + section_length]):
                    continue

                # now were reasonably certain we've got a correct packet
                # we'll convert the rest of the packet
                e = [ord(data[i]) for i in range(0, 10)]

                timeNow = list(parseMJD((e[3] << 8) + e[4]))
                timeNow.extend([unBCD(e[5]), unBCD(e[6]), unBCD(e[7])])

                descriptors_length = ((e[8] << 8) + e[9]) & 0x0fff
                i = 10
                descriptors_end = i + descriptors_length
                while i < descriptors_end:
                    (dtype, descriptor), i = parseDescriptor(i, data)
                    if descriptor['type'] == "local_time_offset":
                        table = {
                            "table_type": "TOT",
                            "UTC_now": timeNow,
                            "offset": descriptor['offset'],
                            "next": {
                                "offset": descriptor['nextOffset'],
                                "when": descriptor['timeOfChange'],
                            },
                            "country": descriptor['country'],
                            "region": descriptor['region'],
                        }

                        self.send(table, "outbox")

            self.pause()
            yield 1
Пример #2
0
    def main(self):
        while not self.shutdown():

            while self.dataReady("inbox"):
                data = self.recv("inbox")

                # extract basic info from this PSI packet - enough to work
                # out what table it is; what section, and the version
                e = [ord(data[i]) for i in range(0,3) ]

                table_id = e[0]
                if table_id != 0x73:
                    continue

                syntax = e[1] & 0x80
                if syntax:
                    continue

                section_length = ((e[1]<<8) + e[2]) & 0x0fff

                if not dvbcrc(data[:3+section_length]):
                    continue
                
                # now were reasonably certain we've got a correct packet
                # we'll convert the rest of the packet
                e = [ord(data[i]) for i in range(0,10) ]
                
                timeNow = list( parseMJD((e[3]<<8) + e[4]) )
                timeNow.extend( [unBCD(e[5]), unBCD(e[6]), unBCD(e[7])] )
                
                descriptors_length = ((e[8]<<8) + e[9]) & 0x0fff
                i = 10
                descriptors_end = i + descriptors_length
                while i < descriptors_end:
                    (dtype,descriptor),i = parseDescriptor(i,data)
                    if descriptor['type'] == "local_time_offset":
                        table = { "table_type" : "TOT",
                                  "UTC_now"    : timeNow,
                                  "offset"     : descriptor['offset'],
                                  "next"       : { "offset" : descriptor['nextOffset'],
                                                   "when"   : descriptor['timeOfChange'],
                                                 },
                                  "country"    : descriptor['country'],
                                  "region"     : descriptor['region'],
                                }

                        self.send(table, "outbox")

            self.pause()
            yield 1
    def main(self):
        # initialise buffers
        # ...for holding table sections (until we get  complete table)
        
        # indexed by (table_id, current_next, transport_stream_id, original_network_id)
        sections_found = {}
        latest_versions = {}
        last_section_numbers = {}
        
        while not self.shutdown():
             
            while self.dataReady("inbox"):
                data = self.recv("inbox")
                
                # extract basic info from this PSI packet - enough to work
                # out what table it is; what section, and the version
                e = [ord(data[i]) for i in range(0,3) ]
                
                table_id = e[0]
                if table_id not in self.acceptTables.keys():
                    continue
                
                syntax = e[1] & 0x80
                if not syntax:
                    continue
                section_length = ((e[1]<<8) + e[2]) & 0x0fff
                
                # now were reasonably certain we've got a correct packet
                # we'll convert the rest of the packet
                e = [ord(data[i]) for i in range(0,12) ]
                
                service_id = (e[3]<<8) + e[4]
                
                version = (e[5] & 0x3e)  # no need to >> 1
                current_next = e[5] & 0x01
                section_number = e[6]
                last_section_number = e[7]

                transport_stream_id = (e[8]<<8) + e[9]
                original_network_id  = (e[10]<<8) + e[11]
                
                index = (table_id, service_id, current_next, transport_stream_id, original_network_id)

                # if version number has changed, flush out all previously fetched tables
                crcpass = False
                if version != latest_versions.get(index,-1):
                    if not dvbcrc(data[:3+section_length]):
                        continue
                    else:
                        crcpass = True
                    latest_versions[index] = version
                    
                    sections_found[index] = [False]*(last_section_number+1)
                
#                 if index[0] == 0x50:
#                     print index, section_number
                if not sections_found[index][section_number]:
                    if crcpass or dvbcrc(data[:3+section_length]):
                        
                        sections_found[index][section_number] = True
                        
                        # because of interesting decisions regarding subtable segments
                        # in the spec (EN 300 468, page 22) we have no way of knowing if
                        # we have received the whole table, so we're just going to parse
                        # each fragment we get and output it (if we've not seen it before)
                        tablesection = self.parseTableSection(index, (data, section_length))
#                       print table['actual_other'], table['pf_schedule']
                        self.send( tablesection, "outbox")
                    else:
                        pass  # ignore data with a bad crc
                        
            self.pause()
            yield 1
    def main(self):
        # initialise buffers
        # ...for holding table sections (until we get  complete table)
        
        # indexed by (table_id, current_next, transport_stream_id, original_network_id)
        sections = {}
        latest_versions = {}
        last_section_numbers = {}
        missing_sections_count = {}
        
        while not self.shutdown():
             
            while self.dataReady("inbox"):
                data = self.recv("inbox")
                
                # extract basic info from this PSI packet - enough to work
                # out what table it is; what section, and the version
                e = [ord(data[i]) for i in (0,1,2) ]

                table_id = e[0]
                if table_id not in self.acceptTables.keys():
                    continue
                
                syntax = e[1] & 0x80
                if not syntax:
                    continue
                
                section_length = ((e[1]<<8) + e[2]) & 0x0fff
                
                # now were reasonably certain we've got a correct packet
                # we'll convert the rest of the packet
                e = [ord(data[i]) for i in (0,1,2,3,4,5,6,7) ]
                
                network_id = (e[3]<<8) + e[4]
                version = (e[5] &0x3e)  # no need to >> 1
                current_next = e[5] & 0x01
                section_number = e[6]
                last_section_number = e[7]
                
                index = (table_id, current_next, network_id)

                # if version number has changed, flush out all previously fetched tables
                crcpass = False
                if version != latest_versions.get(index,-1):
                    if not dvbcrc(data[:3+section_length]):
                        continue
                    else:
                        crcpass = True
                    latest_versions[index] = version
                    
                    sections[index] = [None]*(last_section_number+1)
                    missing_sections_count[index] = last_section_number+1
                
                if sections[index][section_number] == None:
                    if crcpass or dvbcrc(data[:3+section_length]):
                        
                        sections[index][section_number] = (data, section_length)
                        missing_sections_count[index] -= 1
                        
                        # see if we have all sections of the table
                        # if we do, send the whole bundle onwards
                        if missing_sections_count[index] == 0:
                            table = self.parseTable(index, sections[index])
                            self.send( table, "outbox")
                        
            self.pause()
            yield 1
Пример #5
0
    def main(self):
        # initialise buffers
        # ...for holding table sections (until we get  complete table)

        # indexed by (table_id, current_next, transport_stream_id, original_network_id)
        sections_found = {}
        latest_versions = {}
        last_section_numbers = {}

        while not self.shutdown():

            while self.dataReady("inbox"):
                data = self.recv("inbox")

                # extract basic info from this PSI packet - enough to work
                # out what table it is; what section, and the version
                e = [ord(data[i]) for i in range(0, 3)]

                table_id = e[0]
                if table_id not in self.acceptTables.keys():
                    continue

                syntax = e[1] & 0x80
                if not syntax:
                    continue
                section_length = ((e[1] << 8) + e[2]) & 0x0fff

                # now were reasonably certain we've got a correct packet
                # we'll convert the rest of the packet
                e = [ord(data[i]) for i in range(0, 12)]

                service_id = (e[3] << 8) + e[4]

                version = (e[5] & 0x3e)  # no need to >> 1
                current_next = e[5] & 0x01
                section_number = e[6]
                last_section_number = e[7]

                transport_stream_id = (e[8] << 8) + e[9]
                original_network_id = (e[10] << 8) + e[11]

                index = (table_id, service_id, current_next,
                         transport_stream_id, original_network_id)

                # if version number has changed, flush out all previously fetched tables
                crcpass = False
                if version != latest_versions.get(index, -1):
                    if not dvbcrc(data[:3 + section_length]):
                        continue
                    else:
                        crcpass = True
                    latest_versions[index] = version

                    sections_found[index] = [False] * (last_section_number + 1)


#                 if index[0] == 0x50:
#                     print index, section_number

                if not sections_found[index][section_number]:
                    if crcpass or dvbcrc(data[:3 + section_length]):

                        sections_found[index][section_number] = True

                        # because of interesting decisions regarding subtable segments
                        # in the spec (EN 300 468, page 22) we have no way of knowing if
                        # we have received the whole table, so we're just going to parse
                        # each fragment we get and output it (if we've not seen it before)
                        tablesection = self.parseTableSection(
                            index, (data, section_length))
                        #                       print table['actual_other'], table['pf_schedule']
                        tablesection["version"] = latest_versions[index]
                        tablesection["section"] = section_number
                        tablesection["last_section"] = len(
                            sections_found[index]) - 1
                        self.send(tablesection, "outbox")
                    else:
                        pass  # ignore data with a bad crc

            self.pause()
            yield 1
    def main(self):
        # initialise buffers
        # ...for holding table sections (until we get  complete table)
        # two sets of each buffer - one for 'next' and 'current' respectively
        sections = [ [],[] ]
        latest_versions = [-1,-1]
        last_section_numbers = [0,0]
        missing_sections_count = [0,0]
        
        while not self.shutdown():
             
            while self.dataReady("inbox"):
                data = self.recv("inbox")
                
                # extract basic info from this PSI packet - enough to work
                # out what table it is; what section, and the version
                e = [ord(data[i]) for i in (0,1,2) ]

                table_id = e[0]
                if table_id != 2:
                    continue
                
                syntax = e[1] & 0x80
                if not syntax:
                    continue
                
                section_length = ((e[1]<<8) + e[2]) & 0x0fff
                
                # now were reasonably certain we've got a correct packet
                # we'll convert the rest of the packet
                e = [ord(data[i]) for i in (0,1,2,5,6,7) ]

                version = (e[3] &0x3e)  # no need to >> 1
                current_next = e[3] & 0x01
                section_number = e[4]
                last_section_number = e[5]

                # if version number has changed, flush out all previously fetched tables
                crcpass = False
                if version != latest_versions[current_next]:
                    if not dvbcrc(data[:3+section_length]):
                        continue
                    else:
                        crcpass = True
                    latest_versions[current_next] = version
                    
                    sections[current_next] = [None]*(last_section_number+1)
                    missing_sections_count[current_next] = last_section_number+1
                
                if sections[current_next][section_number] == None:
                    if crcpass or dvbcrc(data[:3+section_length]):
                        
                        sections[current_next][section_number] = (data, section_length)
                        missing_sections_count[current_next] -= 1
                        
                        # see if we have all sections of the table
                        # if we do, send the whole bundle onwards
                        if missing_sections_count[current_next] == 0:
                            table = self.parseTable(table_id, current_next, sections[current_next])
                            self.send( table, "outbox")
                        
            self.pause()
            yield 1
Пример #7
0
    def main(self):
        # initialise buffers
        # ...for holding table sections (until we get  complete table)
        # two sets of each buffer - one for 'next' and 'current' respectively
        sections = [[], []]
        latest_versions = [-1, -1]
        last_section_numbers = [0, 0]
        missing_sections_count = [0, 0]

        while not self.shutdown():

            while self.dataReady("inbox"):
                data = self.recv("inbox")

                # extract basic info from this PSI packet - enough to work
                # out what table it is; what section, and the version
                e = [ord(data[i]) for i in (0, 1, 2)]

                table_id = e[0]
                if table_id != 0:
                    continue

                syntax = e[1] & 0x80
                if not syntax:
                    continue

                section_length = ((e[1] << 8) + e[2]) & 0x0fff

                # now were reasonably certain we've got a correct packet
                # we'll convert the rest of the packet
                e = [ord(data[i]) for i in (0, 1, 2, 5, 6, 7)]

                version = (e[3] & 0x3e)  # no need to >> 1
                current_next = e[3] & 0x01
                section_number = e[4]
                last_section_number = e[5]

                # if version number has changed, flush out all previously fetched tables
                crcpass = False
                if version != latest_versions[current_next]:
                    if not dvbcrc(data[:3 + section_length]):
                        continue
                    else:
                        crcpass = True
                    latest_versions[current_next] = version

                    sections[current_next] = [None] * (last_section_number + 1)
                    missing_sections_count[
                        current_next] = last_section_number + 1

                if sections[current_next][section_number] == None:
                    if crcpass or dvbcrc(data[:3 + section_length]):

                        sections[current_next][section_number] = (
                            data, section_length)
                        missing_sections_count[current_next] -= 1

                        # see if we have all sections of the table
                        # if we do, send the whole bundle onwards
                        if missing_sections_count[current_next] == 0:
                            table = self.parseTable(table_id, current_next,
                                                    sections[current_next])
                            self.send(table, "outbox")

            self.pause()
            yield 1
Пример #8
0
    def main(self):
        # initialise buffers
        # ...for holding table sections (until we get  complete table)

        # indexed by (table_id, current_next, transport_stream_id, original_network_id)
        sections = {}
        latest_versions = {}
        last_section_numbers = {}
        missing_sections_count = {}

        while not self.shutdown():

            while self.dataReady("inbox"):
                data = self.recv("inbox")

                # extract basic info from this PSI packet - enough to work
                # out what table it is; what section, and the version
                e = [ord(data[i]) for i in (0, 1, 2)]

                table_id = e[0]
                if table_id not in self.acceptTables.keys():
                    continue

                syntax = e[1] & 0x80
                if not syntax:
                    continue

                section_length = ((e[1] << 8) + e[2]) & 0x0fff

                # now were reasonably certain we've got a correct packet
                # we'll convert the rest of the packet
                e = [ord(data[i]) for i in (0, 1, 2, 3, 4, 5, 6, 7)]

                network_id = (e[3] << 8) + e[4]
                version = (e[5] & 0x3e)  # no need to >> 1
                current_next = e[5] & 0x01
                section_number = e[6]
                last_section_number = e[7]

                index = (table_id, current_next, network_id)

                # if version number has changed, flush out all previously fetched tables
                crcpass = False
                if version != latest_versions.get(index, -1):
                    if not dvbcrc(data[:3 + section_length]):
                        continue
                    else:
                        crcpass = True
                    latest_versions[index] = version

                    sections[index] = [None] * (last_section_number + 1)
                    missing_sections_count[index] = last_section_number + 1

                if sections[index][section_number] == None:
                    if crcpass or dvbcrc(data[:3 + section_length]):

                        sections[index][section_number] = (data,
                                                           section_length)
                        missing_sections_count[index] -= 1

                        # see if we have all sections of the table
                        # if we do, send the whole bundle onwards
                        if missing_sections_count[index] == 0:
                            table = self.parseTable(index, sections[index])
                            self.send(table, "outbox")

            self.pause()
            yield 1