Beispiel #1
0
def describe(parsed):
    """ Describe all elements in Asterix data in textual format.
    Args:
        parsed: Parsed Asterix packet returned by ateris.parse
    Returns:
         Formatted string describing all Asterix data
    """
    i = 0
    txt = ''
    for record in parsed:
        i += 1
        txt += '\n\nAsterix record: %d ' % i
        len = record['len']
        txt += '\nLen: %ld' % (len)
        crc = record['crc']
        txt += '\nCRC: %s' % (crc)
        ts = record['ts']
        strts = datetime.fromtimestamp(ts / 1000.)

        txt += '\nTimestamp: %ld (%s)' % (ts, strts)
        cat = record['category']
        txt += '\nCategory: %d (%s)' % (cat, _asterix.describe(cat))
        txt += '\nHexdata: %s' % record['hexdata']

        for key, value in record.items():
            if key != 'category':
                if isinstance(value, dict):
                    for ikey, ival in value.items():
                        txt += '\nItem: %s (%s)' % (
                            str(key), _asterix.describe(cat, str(key)))

                        if 'val' in ival:
                            txt += '\n\t%s (%s): %s %s' % (
                                ikey, _asterix.describe(
                                    cat, str(key), ikey), str(ival['val']),
                                _asterix.describe(cat, str(key), ikey,
                                                  str(ival['val'])))
                        else:
                            txt += '\n\t%s' % ikey
                            for ikey2, ival2 in ival.items():
                                txt += '\n\t\t%s (%s): %s %s' % (
                                    ikey2,
                                    _asterix.describe(cat, str(key), ikey2),
                                    str(ival2['val']),
                                    _asterix.describe(cat, str(key), ikey2,
                                                      str(ival2['val'])))
                elif isinstance(value, list):
                    txt += '\nItem: %s (%s)' % (
                        str(key), _asterix.describe(cat, str(key)))

                    for it in value:
                        for ikey, ival in it.items():
                            txt += '\n\t%s (%s): %s %s' % (
                                ikey, _asterix.describe(
                                    cat, str(key), ikey), str(ival['val']),
                                _asterix.describe(cat, str(key), ikey,
                                                  str(ival['val'])))

    return txt
Beispiel #2
0
def describe(category, item=None, field=None, value=None):
    """ Return the description of specific Category, Item, Field and Value in Asterix specification
    Args:
        category: Asterix category (e.g. 62)
        item: Asterix Item ID (e.g. 'I010')
        field: Asterix field name (e.g. 'SAC')
        value: Asterix field value meaning (e.g. 1)

    """
    if value:
        return _asterix.describe(category, item, field, value)
    elif field:
        return _asterix.describe(category, item, field)
    elif item:
        return _asterix.describe(category, item)
    return _asterix.describe(category)
Beispiel #3
0
def describe(category, item=None, field=None, value=None):
    """ Return the description of specific Category, Item, Field and Value in Asterix specification
    Args:
        category: Asterix category (e.g. 62)
        item: Asterix Item ID (e.g. 'I010')
        field: Asterix field name (e.g. 'SAC')
        value: Asterix field value meaning (e.g. 1)

    """
    if value:
        return _asterix.describe(category, item, field, value)
    elif field:
        return _asterix.describe(category, item, field)
    elif item:
        return _asterix.describe(category, item)
    return _asterix.describe(category)
Beispiel #4
0
def describe(parsed):
    """ Describe all elements in Asterix data in textual format.
    Args:
        parsed: Parsed Asterix packet returned by ateris.parse
    Returns:
         Formatted string describing all Asterix data
    """
    i = 0
    txt = ''
    for record in parsed:
        i+=1
        txt += '\n\nAsterix record: %d ' % i
        len = record['len']
        txt += '\nLen: %ld' % (len)
        crc = record['crc']
        txt += '\nCRC: %s' % (crc)
        ts = record['ts']
        strts = datetime.fromtimestamp(ts/1000.)

        txt += '\nTimestamp: %ld (%s)' % (ts, strts)
        cat = record['category']
        txt += '\nCategory: %d (%s)' % (cat, _asterix.describe(cat))

        for key, value in record.items():
            if key != 'category':
                txt += '\nItem: %s (%s)' % (str(key), _asterix.describe(cat, str(key)))
                if isinstance(value, dict):
                    for ikey, ival in value.items():
                        if 'val' in ival:
                            txt += '\n\t%s (%s): %s %s' % (ikey, _asterix.describe(cat, str(key), ikey), str(ival['val']),_asterix.describe(cat, str(key), ikey, str(ival['val'])))
                        else:
                            txt += '\n\t%s' % ikey
                            for ikey2, ival2 in ival.items():
                                txt += '\n\t\t%s (%s): %s %s' % (ikey2, _asterix.describe(cat, str(key), ikey2), str(ival2['val']), _asterix.describe(cat, str(key), ikey2, str(ival2['val'])))
                elif isinstance(value, list):
                    for it in value:
                        for ikey, ival in it.items():
                            txt += '\n\t%s (%s): %s %s' % (ikey, _asterix.describe(cat, str(key), ikey), str(ival['val']), _asterix.describe(cat, str(key), ikey, str(ival['val'])))
                else:
                    txt += str(value)

    return txt
Beispiel #5
0
def describeXML(parsed, descriptions=False):
    """ Describe all elements in Asterix data in a lxml ElementTree.
    Content is identical to the command "./asterix --xml filename".
    Args:
        parsed: Parsed Asterix packet returned by asterix.parse
    Returns:
         lxml ElementTree describing all Asterix data
         None if lxml module is not installed
    """
    if lxml_found:
        xml = etree.Element('ASTERIXSTART')
        for record in parsed:
            xml_Record = etree.SubElement(xml, 'ASTERIX')
            cat = record['category']
            ts = record['ts']
            xml_Record.set('ver', '%d' % 1)
            xml_Record.set('length', '%ld' % record['len'])
            xml_Record.set('crc', '%s' % record['crc'])
            xml_Record.set('timestamp', '%ld' % ts)
            if 'hexdata' in record:
                xml_Record.set('hexdata', record['hexdata'])
            xml_Record.set('cat', '%03d' % cat)
            if descriptions:
                xml_Record.set('description', '%s' % _asterix.describe(cat))

            for key, value in record.items():
                if key[0] == 'I':
                    xml_Item = etree.SubElement(xml_Record, key)
                    description = '%s' % _asterix.describe(cat, str(key))
                    if description and descriptions:
                        xml_Item.set('description', description)
                    if isinstance(value, dict):
                        for ikey, ival in value.items():
                            xml_Field = etree.SubElement(xml_Item, ikey)
                            if 'val' in ival:
                                description1 = _asterix.describe(
                                    cat, str(key), ikey)
                                description2 = _asterix.describe(
                                    cat, str(key), ikey, str(ival['val']))
                                if description2 and descriptions:
                                    xml_Field.set('description', description2)
                                xml_Field.text = str(ival['val'])
                            else:
                                for ikey2, ival2 in ival.items():
                                    xml_subItem = etree.SubElement(
                                        xml_Field, ikey2)
                                    description1 = _asterix.describe(
                                        cat, str(key), ikey2)
                                    description2 = _asterix.describe(
                                        cat, str(key), ikey2,
                                        str(ival2['val']))
                                    if description2 and descriptions:
                                        xml_subItem.set(
                                            'description', description2)
                                    xml_subItem.text = str(ival2['val'])
                    elif isinstance(value, list):
                        for it in value:
                            for ikey, ival in it.items():
                                xml_Field = etree.SubElement(xml_Item, ikey)
                                description1 = _asterix.describe(
                                    cat, str(key), ikey)
                                description2 = _asterix.describe(
                                    cat, str(key), ikey, str(ival['val']))
                                if description2 and descriptions:
                                    xml_Field.set('description', description2)
                                xml_Field.text = str(ival['val'])
                    else:
                        xml_Item.text = str(value)

        return xml
    return None