Beispiel #1
0
    def testMJD_UTC_Convertion(self):
        #test mjd + utc convertion
        test_data = array.array('B', hex_to_byte("D641 10 29 40"))
        res = dvb_mjd_to_string(None ,  test_data )
        self.assertEqual( "18/1/2009 10:29:40 ", str(res))

        #unlimited
        test_data = array.array('B', hex_to_byte("FFFFFFFFFF"))
        res = dvb_mjd_to_string(None ,  test_data )
        self.assertEqual( "Unlimited", str(res))

        #wrong size
        test_data = array.array('B', hex_to_byte("FFFFFFFF"))
        res = dvb_mjd_to_string(None ,  test_data )
        self.assertEqual( "Didn't parse", str(res))
Beispiel #2
0
def main():
    # set debug level
    if (verbose):
        verbose_level = logging.DEBUG
    else:
        verbose_level = logging.INFO
    # Log everything, and send it to stderr.
    # create logger
    log = logging.getLogger("simple_example")
    log.setLevel(verbose_level)
    # create console handler and set level to debug
    ch = logging.StreamHandler()
    ch.setLevel(verbose_level)
    # create formatter
    formatter = logging.Formatter("%(asctime)s - %(levelname)-8s - %(message)s")
    # add formatter to ch
    ch.setFormatter(formatter)
    # add ch to logger
    log.addHandler(ch)

    log.debug("open file")
    TS_file = openTSFile('''C:\signaling\Xad_14_12.ts''')
    print TS_file
    SeekPacket(TS_file, 1577717)
    for i in range(1000000):
        pack = GetPakcet(TS_file, i)
        data = array.array('B', pack)
        #print len(pack)
        #print ByteToHex(pack)
        try:
            parseTS_Packet(data)
        except ValueError:
            pass
Beispiel #3
0
 def testProfileByte_Convertion(self):
     #test profile byte convertion
     test_data = array.array('B', hex_to_byte("01 000f 01 0014 00 02 01 0002 04 02 00 01 00 08 00 06"))
     test_bs = BitStructureExt('TEST')
     test_bs.set_array(test_data)
     self.assertEqual( 19 ,  len( test_data ) )
     self.assertEqual('!( ( ( A15 < A20 ) and ( A2 == 2 ) ) )',
         ProfileByte_to_string(test_bs, len( test_data ), test_data))
Beispiel #4
0
def dvb_mjd_to_string( bit_structure=None , byte_array=None ):
    '''
    convert 5 byte array to string reprsention time

    from ETSI EN 300 468
    Digital Video Broadcasting (DVB);
    Specification for Service Information (SI) in DVB systems
    '''


    if byte_array is None:
        byte_array = array.array('B', bit_structure.array())

    if len(byte_array) != 5:
        LOG.error("No a DVB MJD: size is not 5 bytes")
        return "Didn't parse"
    elif byte_to_hex(byte_array.tostring()) == "FF FF FF FF FF":
        LOG.error("No a DVB MJD: 0xFFFFFFFFFF")
        return "Unlimited"
    elif byte_to_hex(byte_array.tostring()) == "00 00 00 00 00":
        LOG.error("No a DVB MJD: 0x0000000000")
        return "None"

    LOG.debug( byte_to_hex(byte_array.tostring()))

    bitstruct = BitStructureExt('MJD+UTC')
    bitstruct.append(BitFieldExt('MJD',        BYTE_SIZE * 2))
    bitstruct.append(BitFieldExt('hours',    BYTE_SIZE * 1))
    bitstruct.append(BitFieldExt('mins',    BYTE_SIZE * 1))
    bitstruct.append(BitFieldExt('secs',    BYTE_SIZE * 1))
    bitstruct.set_array (byte_array)
    number = bitstruct['MJD']
    LOG.debug( "dvb_mjd_to_string got MJD: 0x%x" % number)

    y_tag = int((int (number) - 15078.2) / 365.25)
    m_tag = int( (int (number) - 14956.1 - int (y_tag * 365.25) ) / 30.6001 )
    d = int(number) - 14956 - int (y_tag * 365.25) - int (m_tag * 30.6001 )

    if (m_tag == 14) or (m_tag == 15):
        k = 1
    else:
        k = 0
    y = y_tag + k
    m = m_tag - 1 - k * 12

    time_string = "%s/%s/%s %x:%x:%x " % (d, m, 1900+y, 
        bitstruct['hours'], 
        bitstruct['mins'], 
        bitstruct['secs'])
        
    LOG.debug(time_string)

    return time_string
Beispiel #5
0
def main():
    '''main function'''
    params = handle_args()
    configure_debug(params)
    data = None
    # TEST PACKET

    if (params['testing']):
        from xmlrunner import XmlTestRunner
        runner = XmlTestRunner()
        runner.run(unittest.makeSuite(BitGamesTest))
        sys.exit()

    # open a file
    if(params['input_filename'] != None):
        try:
            data_file = open(params['input_filename'])
        except IOError, err:
            print err
            sys.exit(2)

        data = array.array('B', hex_to_byte(data_file.readline()))
Beispiel #6
0
    def testMyPacket(self):
        # my packet
        data = array.array('B', hex_to_byte("000001BD003D8C80052100010001810021050801000101113E80008106110000000000820DA0D100000BB8010104010203040007110000000000000000000000000000"))

        (bs, data) = ParsePacket_No_TS_Header(data)
        print bs
Beispiel #7
0
    def testStreamPacket(self):
        # stream packet
        data = array.array('B', hex_to_byte("000001bd002e8180052b925721bd860021050801000178d17f88008106c3001323d400820d9fc3000002ee010104000000010000"))

        (bs, data) = ParsePacket_No_TS_Header(data)
        print bs
Beispiel #8
0
 def testDavidPacket(self):
     # david packet
     data = array.array('B', hex_to_byte("000001bd008b8c80052100010001810021050801000101113e80008106030000000000820d80c300000bb801010401020304005711ffffffffff018000000001020000000000ffffffffff 13 01000f01001400020100020402000100080006 01000000000102ee0000000000ffffffffff13 01000f0100140002010002040200010008000601000000000102ee00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"))
     (bs, data) = ParsePacket_No_TS_Header(data)
     print bs
Beispiel #9
0
def ProfileByte_to_string ( profileByte , length , data=None):
    '''
    Parse the profile byte and return a string represntion of it

    Table 3    Data Type Definitions
    DataType Value    Data Length    Mnemonic    Description
    0x00    8 bits    uimsbf    This specifies that the proceeding data byte defines an evaluation that should take place. The set of valid values is defined in Table 4

    0x01    16 bits    uimsbf (MSBF)    This signals that the data represents a Profile attribute. The STB shall retrieve the value associated with this Profile Attribute.
    0x02    16 bits    uimsbf (MSBF)    A 16 bit unsigned int value
    0x03    32 bits    uimsbf (MSBF)    A 32 bit unsigned int value
    0x04    8 bits    uimsbf (MSBF)    An 8 bit unsigned int value
    0x05    variable    blsbf    A null terminated ASCII string of variable length.


    Table 4    Operator data values
    Data Value    Description
    0x01    Signals an "equals" comparison
    0x02     Signals a "less than" comparison
    0x03    Signals a "greater than" comparison
    0x04    Signals a "less than or equals" comparison
    0x05    Signals a "greater than or equals" comparison
    0x06    Signals a "not" comparison
    0x07    Signals a "not equals" comparison
    0x08    Signals an "AND"  comparison
    0x09    Signals an "OR" comparison
    '''
    operators = [ "==", "<", ">", "<=", ">=", "!=", "and", "or"]
    one_opt = ["!"]

    if (data == None):
        data = array.array('B', profileByte.array())

    bs = BitStructureExt("PROFILE")
    byte_to_read = length
    i = 0
    s = []

    while (byte_to_read > 0):
        LOG.debug ("ProfileByte_to_string: byte_to_read = " + str(byte_to_read))
        bs.append(BitFieldExt('Type_' +str(i) ,    BYTE_SIZE * 1))
        byte_to_read -= 1
        bs.set_array(data)
        type = bs['Type_' + str(i) ]
        if (type == 0x0):
            # take 8 bits
            bs.append(BitFieldExt('Value_' +str(i) ,    BIT_SIZE * 8))
            byte_to_read -= 1
            bs.set_array(data)
            predicte = bs['Value_' +str(i)]
            if (predicte == 0x01):
                s.append("==")
            elif (predicte == 0x02):
                s.append("<")
            elif (predicte == 0x03):
                s.append(">")
            elif (predicte == 0x04):
                s.append("<=")
            elif (predicte == 0x05):
                s.append(">=")
            elif (predicte == 0x06):
                s.append("!")
            elif (predicte == 0x07):
                s.append("!=")
            elif (predicte == 0x08):
                s.append("and")
            elif (predicte == 0x09):
                s.append("or")
            else:
                LOG.error ("Not a valid predicte inside a profile Byte: " + str (predicte))
                return "ERROR !!! in ProfileByte_to_string"
        elif (type == 0x1):
            # take 16 bits
            bs.append(BitFieldExt('Value_' +str(i) ,    BYTE_SIZE * 2))
            byte_to_read -= 2
            bs.set_array(data)
            value = bs['Value_' +str(i)]
            s.append("A" + str(value))
        elif (type == 0x2):
            # take 16 bits
            bs.append(BitFieldExt('Value_' +str(i) ,    BYTE_SIZE * 2))
            byte_to_read -= 2
            bs.set_array(data)
            value = bs['Value_' +str(i)]
            s.append(str(value))
        elif (type == 0x3):
            #take 32 bits
            bs.append(BitFieldExt('Value_' +str(i) ,    BYTE_SIZE * 4))
            byte_to_read -= 4
            bs.set_array(data)
            value = bs['Value_' +str(i)]
            s.append(str(value))
        elif (type == 0x4):
            #take 8 bits
            bs.append(BitFieldExt('Value_' +str(i) ,    BIT_SIZE * 8))
            byte_to_read -= 1
            bs.set_array(data)
            value = bs['Value_' +str(i)]
            s.append(str(value))
        elif (type == 0x5):
            # take how to take null terminated ???
            LOG.error ("No Support for null terminated vaule yet. ")
            return "ERROR !!! in ProfileByte_to_string"
        else:
            LOG.error ("No a valid type inside a profile Byte: " + str(type) )
            return "ERROR !!! in ProfileByte_to_string"
        i += 1

    temp_str = ""
    stack = []
    for item in s:
        if item in operators:
            temp_str = "( " + str(stack.pop(-2)) + " " + str(item)+" " +str(stack.pop(-1))+ " )"
            LOG.debug (temp_str)
            stack.append(temp_str)
        elif item in one_opt:
            temp_str = str(item)+"( " +str(stack.pop(-1))+ " )"
            LOG.debug (temp_str)
            stack.append(temp_str)
        else:
            stack.append(item)

    LOG.debug (str(stack))
    #Data Type Definitions

    return str(stack.pop(-1))