asterix: adjust to upstream change

Structure change in asterix-specs, revision 3ab3bb3.
Rule type is generalized and it now also includes a default value.
This commit is contained in:
Zoran Bošnjak 2024-02-26 09:22:51 +01:00
parent e0300eaed8
commit 33c9657365
2 changed files with 65 additions and 50 deletions

View File

@ -9,7 +9,7 @@ See tools/asterix/README.md for details.
Data source: Data source:
https://zoranbosnjak.github.io/asterix-specs https://zoranbosnjak.github.io/asterix-specs
git revision: 941f5ce71b19d4659401e84b83b084505dd53e28 git revision: 3ab3bb3445a27e0a96636ad8f8c8e3134870511c
*/ */
@ -4603,8 +4603,8 @@ static const AsterixField I004_V1_12_120_CN = { FX, 1, 0, 0, &hf_004_V1_12_120_C
static int hf_004_V1_12_120_CC; static int hf_004_V1_12_120_CC;
static int hf_004_V1_12_120_CC_TID; static int hf_004_V1_12_120_CC_TID;
static const FieldPart I004_V1_12_120_CC_TID = { 4, 1.0, FIELD_PART_HEX, &hf_004_V1_12_120_CC_TID, NULL }; static const FieldPart I004_V1_12_120_CC_TID = { 4, 1.0, FIELD_PART_HEX, &hf_004_V1_12_120_CC_TID, NULL };
static int hf_004_V1_12_120_CC_CP; static int hf_004_V1_12_120_CC_CPC;
static const FieldPart I004_V1_12_120_CC_CP = { 3, 1.0, FIELD_PART_HEX, &hf_004_V1_12_120_CC_CP, NULL }; static const FieldPart I004_V1_12_120_CC_CPC = { 3, 1.0, FIELD_PART_HEX, &hf_004_V1_12_120_CC_CPC, NULL };
static int hf_004_V1_12_120_CC_CS; static int hf_004_V1_12_120_CC_CS;
static const value_string valstr_004_V1_12_120_CC_CS[] = { static const value_string valstr_004_V1_12_120_CC_CS[] = {
{ 0, "LOW" }, { 0, "LOW" },
@ -4614,7 +4614,7 @@ static const value_string valstr_004_V1_12_120_CC_CS[] = {
static const FieldPart I004_V1_12_120_CC_CS = { 1, 1.0, FIELD_PART_UINT, &hf_004_V1_12_120_CC_CS, NULL }; static const FieldPart I004_V1_12_120_CC_CS = { 1, 1.0, FIELD_PART_UINT, &hf_004_V1_12_120_CC_CS, NULL };
static const FieldPart *I004_V1_12_120_CC_PARTS[] = { static const FieldPart *I004_V1_12_120_CC_PARTS[] = {
&I004_V1_12_120_CC_TID, &I004_V1_12_120_CC_TID,
&I004_V1_12_120_CC_CP, &I004_V1_12_120_CC_CPC,
&I004_V1_12_120_CC_CS, &I004_V1_12_120_CC_CS,
NULL NULL
}; };
@ -5796,8 +5796,8 @@ static const AsterixField I004_120_CN = { FX, 1, 0, 0, &hf_004_120_CN, I004_120_
static int hf_004_120_CC; static int hf_004_120_CC;
static int hf_004_120_CC_TID; static int hf_004_120_CC_TID;
static const FieldPart I004_120_CC_TID = { 4, 1.0, FIELD_PART_HEX, &hf_004_120_CC_TID, NULL }; static const FieldPart I004_120_CC_TID = { 4, 1.0, FIELD_PART_HEX, &hf_004_120_CC_TID, NULL };
static int hf_004_120_CC_CP; static int hf_004_120_CC_CPC;
static const FieldPart I004_120_CC_CP = { 3, 1.0, FIELD_PART_HEX, &hf_004_120_CC_CP, NULL }; static const FieldPart I004_120_CC_CPC = { 3, 1.0, FIELD_PART_HEX, &hf_004_120_CC_CPC, NULL };
static int hf_004_120_CC_CS; static int hf_004_120_CC_CS;
static const value_string valstr_004_120_CC_CS[] = { static const value_string valstr_004_120_CC_CS[] = {
{ 0, "LOW" }, { 0, "LOW" },
@ -5807,7 +5807,7 @@ static const value_string valstr_004_120_CC_CS[] = {
static const FieldPart I004_120_CC_CS = { 1, 1.0, FIELD_PART_UINT, &hf_004_120_CC_CS, NULL }; static const FieldPart I004_120_CC_CS = { 1, 1.0, FIELD_PART_UINT, &hf_004_120_CC_CS, NULL };
static const FieldPart *I004_120_CC_PARTS[] = { static const FieldPart *I004_120_CC_PARTS[] = {
&I004_120_CC_TID, &I004_120_CC_TID,
&I004_120_CC_CP, &I004_120_CC_CPC,
&I004_120_CC_CS, &I004_120_CC_CS,
NULL NULL
}; };
@ -56683,7 +56683,7 @@ void proto_register_asterix (void)
{ &hf_004_V1_12_120_CN_AIW, { "AIW", "asterix.004_V1_12_120_CN_AIW", FT_UINT8, BASE_DEC, VALS (valstr_004_V1_12_120_CN_AIW), 0x04, NULL, HFILL } }, { &hf_004_V1_12_120_CN_AIW, { "AIW", "asterix.004_V1_12_120_CN_AIW", FT_UINT8, BASE_DEC, VALS (valstr_004_V1_12_120_CN_AIW), 0x04, NULL, HFILL } },
{ &hf_004_V1_12_120_CC, { "CC, Conflict Classification", "asterix.004_V1_12_120_CC", FT_NONE, BASE_NONE, NULL, 0x00, NULL, HFILL } }, { &hf_004_V1_12_120_CC, { "CC, Conflict Classification", "asterix.004_V1_12_120_CC", FT_NONE, BASE_NONE, NULL, 0x00, NULL, HFILL } },
{ &hf_004_V1_12_120_CC_TID, { "TID, Identification of Conflict Categories Definition Table", "asterix.004_V1_12_120_CC_TID", FT_UINT8, BASE_DEC, NULL, 0xf0, NULL, HFILL } }, { &hf_004_V1_12_120_CC_TID, { "TID, Identification of Conflict Categories Definition Table", "asterix.004_V1_12_120_CC_TID", FT_UINT8, BASE_DEC, NULL, 0xf0, NULL, HFILL } },
{ &hf_004_V1_12_120_CC_CP, { "CP, Conflict Properties Class", "asterix.004_V1_12_120_CC_CP", FT_UINT8, BASE_DEC, NULL, 0x0e, NULL, HFILL } }, { &hf_004_V1_12_120_CC_CPC, { "CPC, Conflict Properties Class", "asterix.004_V1_12_120_CC_CPC", FT_UINT8, BASE_DEC, NULL, 0x0e, NULL, HFILL } },
{ &hf_004_V1_12_120_CC_CS, { "CS, Conflict Severity", "asterix.004_V1_12_120_CC_CS", FT_UINT8, BASE_DEC, VALS (valstr_004_V1_12_120_CC_CS), 0x01, NULL, HFILL } }, { &hf_004_V1_12_120_CC_CS, { "CS, Conflict Severity", "asterix.004_V1_12_120_CC_CS", FT_UINT8, BASE_DEC, VALS (valstr_004_V1_12_120_CC_CS), 0x01, NULL, HFILL } },
{ &hf_004_V1_12_120_CP, { "CP, Conflict Probability", "asterix.004_V1_12_120_CP", FT_NONE, BASE_NONE, NULL, 0x00, NULL, HFILL } }, { &hf_004_V1_12_120_CP, { "CP, Conflict Probability", "asterix.004_V1_12_120_CP", FT_NONE, BASE_NONE, NULL, 0x00, NULL, HFILL } },
{ &hf_004_V1_12_120_CP_VALUE, { "Conflict Probability, [%]", "asterix.004_V1_12_120_CP_VALUE", FT_DOUBLE, BASE_NONE, NULL, 0x00, NULL, HFILL } }, { &hf_004_V1_12_120_CP_VALUE, { "Conflict Probability, [%]", "asterix.004_V1_12_120_CP_VALUE", FT_DOUBLE, BASE_NONE, NULL, 0x00, NULL, HFILL } },
@ -56880,7 +56880,7 @@ void proto_register_asterix (void)
{ &hf_004_120_CN_AIW, { "AIW", "asterix.004_120_CN_AIW", FT_UINT8, BASE_DEC, VALS (valstr_004_120_CN_AIW), 0x04, NULL, HFILL } }, { &hf_004_120_CN_AIW, { "AIW", "asterix.004_120_CN_AIW", FT_UINT8, BASE_DEC, VALS (valstr_004_120_CN_AIW), 0x04, NULL, HFILL } },
{ &hf_004_120_CC, { "CC, Conflict Classification", "asterix.004_120_CC", FT_NONE, BASE_NONE, NULL, 0x00, NULL, HFILL } }, { &hf_004_120_CC, { "CC, Conflict Classification", "asterix.004_120_CC", FT_NONE, BASE_NONE, NULL, 0x00, NULL, HFILL } },
{ &hf_004_120_CC_TID, { "TID, Identification of Conflict Categories Definition Table", "asterix.004_120_CC_TID", FT_UINT8, BASE_DEC, NULL, 0xf0, NULL, HFILL } }, { &hf_004_120_CC_TID, { "TID, Identification of Conflict Categories Definition Table", "asterix.004_120_CC_TID", FT_UINT8, BASE_DEC, NULL, 0xf0, NULL, HFILL } },
{ &hf_004_120_CC_CP, { "CP, Conflict Properties Class", "asterix.004_120_CC_CP", FT_UINT8, BASE_DEC, NULL, 0x0e, NULL, HFILL } }, { &hf_004_120_CC_CPC, { "CPC, Conflict Properties Class", "asterix.004_120_CC_CPC", FT_UINT8, BASE_DEC, NULL, 0x0e, NULL, HFILL } },
{ &hf_004_120_CC_CS, { "CS, Conflict Severity", "asterix.004_120_CC_CS", FT_UINT8, BASE_DEC, VALS (valstr_004_120_CC_CS), 0x01, NULL, HFILL } }, { &hf_004_120_CC_CS, { "CS, Conflict Severity", "asterix.004_120_CC_CS", FT_UINT8, BASE_DEC, VALS (valstr_004_120_CC_CS), 0x01, NULL, HFILL } },
{ &hf_004_120_CP, { "CP, Conflict Probability", "asterix.004_120_CP", FT_NONE, BASE_NONE, NULL, 0x00, NULL, HFILL } }, { &hf_004_120_CP, { "CP, Conflict Probability", "asterix.004_120_CP", FT_NONE, BASE_NONE, NULL, 0x00, NULL, HFILL } },
{ &hf_004_120_CP_VALUE, { "Conflict Probability, [%]", "asterix.004_120_CP_VALUE", FT_DOUBLE, BASE_NONE, NULL, 0x00, NULL, HFILL } }, { &hf_004_120_CP_VALUE, { "Conflict Probability, [%]", "asterix.004_120_CP_VALUE", FT_DOUBLE, BASE_NONE, NULL, 0x00, NULL, HFILL } },

View File

@ -261,14 +261,12 @@ def reference(cat, edition, path):
return('{:03d}_{}'.format(cat, name)) return('{:03d}_{}'.format(cat, name))
return('{:03d}_V{}_{}_{}'.format(cat, edition['major'], edition['minor'], name)) return('{:03d}_V{}_{}_{}'.format(cat, edition['major'], edition['minor'], name))
def get_content(rule): def get_rule(rule):
t = rule['type'] t = rule['type']
# Most cases are 'ContextFree', use as specified.
if t == 'ContextFree': if t == 'ContextFree':
return rule['content'] return rule['value']
# Handle 'Dependent' contents as 'Raw'.
elif t == 'Dependent': elif t == 'Dependent':
return {'type': "Raw"} return rule['default']
else: else:
raise Exception('unexpected type: {}'.format(t)) raise Exception('unexpected type: {}'.format(t))
@ -277,7 +275,7 @@ def get_bit_size(item):
if item['spare']: if item['spare']:
return item['length'] return item['length']
else: else:
return item['variation']['size'] return get_rule(item['rule'])['size']
def get_description(item, content=None): def get_description(item, content=None):
"""Return item description.""" """Return item description."""
@ -300,12 +298,18 @@ def generate_group(item, variation=None):
level2['is_generated'] = True level2['is_generated'] = True
if variation is None: if variation is None:
level1 = copy(item) level1 = copy(item)
level1['variation'] = { level1['rule'] = {
'type': 'Group', 'type': 'ContextFree',
'items': [level2], 'value': {
'type': 'Group',
'items': [level2],
},
} }
else: else:
level2['variation'] = variation['variation'] level2['rule'] = {
'type': 'ContextFree',
'value': variation,
}
level1 = { level1 = {
'type': "Group", 'type': "Group",
'items': [level2], 'items': [level2],
@ -317,15 +321,18 @@ def is_generated(item):
def ungroup(item): def ungroup(item):
"""Convert group of items of known size to element""" """Convert group of items of known size to element"""
n = sum([get_bit_size(i) for i in item['variation']['items']]) n = sum([get_bit_size(i) for i in get_rule(item['rule'])['items']])
result = copy(item) result = copy(item)
result['variation'] = { result['rule'] = {
'rule': { 'type': 'ContextFree',
'content': {'type': 'Raw'}, 'value': {
'type': 'ContextFree', 'type': 'Element',
'size': n,
'rule': {
'type': 'ContextFree',
'value': {'type': 'Raw'},
},
}, },
'size': n,
'type': 'Element',
} }
return result return result
@ -363,7 +370,7 @@ def part1(ctx, get_ref, catalogue):
if t == 'Element': if t == 'Element':
tell('static int hf_{};'.format(ref)) tell('static int hf_{};'.format(ref))
n = variation['size'] n = variation['size']
content = get_content(variation['rule']) content = get_rule(variation['rule'])
scaling = get_scaling(content) scaling = get_scaling(content)
scaling = scaling if scaling is not None else 1.0 scaling = scaling if scaling is not None else 1.0
fp = get_fieldpart(content) fp = get_fieldpart(content)
@ -421,8 +428,8 @@ def part1(ctx, get_ref, catalogue):
if i is None: if i is None:
items.append(i) items.append(i)
continue continue
if i.get('variation') is not None: if i.get('rule') is not None:
if i['variation']['type'] == 'Group': if get_rule(i['rule'])['type'] == 'Group':
i = ungroup(i) i = ungroup(i)
items.append(i) items.append(i)
@ -456,7 +463,7 @@ def part1(ctx, get_ref, catalogue):
# Group is required below this item. # Group is required below this item.
if variation['variation']['type'] == 'Element': if variation['variation']['type'] == 'Element':
subvar = generate_group(item, variation) subvar = generate_group(item, variation['variation'])
else: else:
subvar = variation['variation'] subvar = variation['variation']
handle_variation(path, subvar) handle_variation(path, subvar)
@ -489,7 +496,7 @@ def part1(ctx, get_ref, catalogue):
comp += ' &IX_SPARE,' comp += ' &IX_SPARE,'
continue continue
# Group is required below this item. # Group is required below this item.
if i['variation']['type'] == 'Element': if get_rule(i['rule'])['type'] == 'Element':
subitem = generate_group(i) subitem = generate_group(i)
else: else:
subitem = i subitem = i
@ -509,30 +516,36 @@ def part1(ctx, get_ref, catalogue):
return return
# Group is required on the first level. # Group is required on the first level.
if path == [] and item['variation']['type'] == 'Element': if path == [] and get_rule(item['rule'])['type'] == 'Element':
variation = generate_group(item)['variation'] variation = get_rule(generate_group(item)['rule'])
else: else:
variation = item['variation'] variation = get_rule(item['rule'])
handle_variation(path + [item['name']], variation) handle_variation(path + [item['name']], variation)
for item in catalogue: for item in catalogue:
# adjust 'repetitive fx' item # adjust 'repetitive fx' item
if item['variation']['type'] == 'Repetitive' and item['variation']['rep']['type'] == 'Fx': if get_rule(item['rule'])['type'] == 'Repetitive' and get_rule(item['rule'])['rep']['type'] == 'Fx':
var = item['variation']['variation'].copy() var = get_rule(item['rule'])['variation'].copy()
if var['type'] != 'Element': if var['type'] != 'Element':
raise Exception("Expecting 'Element'") raise Exception("Expecting 'Element'")
item = item.copy() item = item.copy()
item['variation'] = { item['rule'] = {
'type': 'Extended', 'type': 'ContextFree',
'items': [{ 'value': {
'definition': None, 'type': 'Extended',
'description': None, 'items': [{
'name': 'Subitem', 'definition': None,
'remark': None, 'description': None,
'spare': False, 'name': 'Subitem',
'title': 'Subitem', 'remark': None,
'variation': var, 'spare': False,
'title': 'Subitem',
'rule': {
'type': 'ContextFree',
'value': var,
},
}, None] }, None]
}
} }
handle_item([], item) handle_item([], item)
tell('') tell('')
@ -647,7 +660,7 @@ def remove_rfs(spec):
catalogue = [] # create new catalogue without RFS catalogue = [] # create new catalogue without RFS
rfs_items = [] rfs_items = []
for i in spec['catalogue']: for i in spec['catalogue']:
if i['variation']['type'] == 'Rfs': if get_rule(i['rule'])['type'] == 'Rfs':
rfs_items.append(i['name']) rfs_items.append(i['name'])
else: else:
catalogue.append(i) catalogue.append(i)
@ -680,7 +693,7 @@ def is_valid(spec):
def check_item(item): def check_item(item):
if item['spare']: if item['spare']:
return True return True
return check_variation(item['variation']) return check_variation(get_rule(item['rule']))
def check_variation(variation): def check_variation(variation):
t = variation['type'] t = variation['type']
if t == 'Element': if t == 'Element':
@ -744,13 +757,15 @@ def main():
for spec in jsons: for spec in jsons:
is_latest = spec['edition'] == latest_editions[spec['number']] is_latest = spec['edition'] == latest_editions[spec['number']]
ctx.tell('insert1', '/* Category {:03d}, edition {}.{} */'.format(spec['number'], spec['edition']['major'], spec['edition']['minor'])) ctx.tell('insert1', '/* Category {:03d}, edition {}.{} */'.format(
spec['number'], spec['edition']['major'], spec['edition']['minor']))
# handle part1 # handle part1
get_ref = lambda path: reference(spec['number'], spec['edition'], path) get_ref = lambda path: reference(spec['number'], spec['edition'], path)
part1(ctx, get_ref, spec['catalogue']) part1(ctx, get_ref, spec['catalogue'])
if is_latest: if is_latest:
ctx.tell('insert1', '/* Category {:03d}, edition {}.{} (latest) */'.format(spec['number'], spec['edition']['major'], spec['edition']['minor'])) ctx.tell('insert1', '/* Category {:03d}, edition {}.{} (latest) */'.format(
spec['number'], spec['edition']['major'], spec['edition']['minor']))
get_ref = lambda path: reference(spec['number'], None, path) get_ref = lambda path: reference(spec['number'], None, path)
part1(ctx, get_ref, spec['catalogue']) part1(ctx, get_ref, spec['catalogue'])