Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/CroatiaControlLtd/asterix
Browse files Browse the repository at this point in the history
…into master
  • Loading branch information
dsalantic committed Mar 25, 2024
2 parents 82cc63e + af22984 commit 9f5a5ac
Show file tree
Hide file tree
Showing 61 changed files with 17,280 additions and 816 deletions.
12 changes: 9 additions & 3 deletions HISTORY
@@ -1,7 +1,7 @@
Version History for Asterix
===========================
0
2005-2013
0
2005-2013
Converter project.

1.0.0
Expand Down Expand Up @@ -259,4 +259,10 @@ Issue #202 Segmentation fault in python when explicit item is wrong

2.8.4 (python_v0.7.4)
Issue #207 Timestamp not created correctly
Added support for python 3.10
Added support for python 3.10

2.8.5 (python_v0.7.5)
Issue #209 replace asterix2json with asterixjson2xml in documentation
Issue #211 asterix-specs conversion fix
Issue #213 Fixed duplicate field names in I001/060 and I252/110
Issue #220 Correct CAT205 and CAT025
12 changes: 6 additions & 6 deletions asterix-specs-converter/README.md
Expand Up @@ -35,9 +35,9 @@ using a script from this directory.
In case of problems in asterix definitions, users of this project are
encouraged to report problems upstream.

## Running `asterix2json.py` script
## Running `asterixjson2xml.py` script

> **_NOTE:_** `asterix2json.py` script requires `python36` or higher.
> **_NOTE:_** `asterixjson2xml.py` script requires `python36` or higher.
### Basic conversion example:

Expand All @@ -49,16 +49,16 @@ python3 --version
curl https://zoranbosnjak.github.io/asterix-specs/specs/cat062/cats/cat1.18/definition.json > input.json

# convert json to xml
python3 asterix2json.py < input.json > output.xml
python3 asterixjson2xml.py < input.json > output.xml

# or directly
curl https://zoranbosnjak.github.io/asterix-specs/specs/cat062/cats/cat1.18/definition.json | python3 asterix2json.py
curl https://zoranbosnjak.github.io/asterix-specs/specs/cat062/cats/cat1.18/definition.json | python3 asterixjson2xml.py
```

### Combine CAT+REF definition to a single xml:

```bash
python3 asterix2json.py --cat category.json --ref ref.json --outfile out.xml
python3 asterixjson2xml.py --cat category.json --ref ref.json --outfile out.xml
```
## Running `update-specs.py` script
This scripts autimatically reads latest Asterix specifications from
Expand All @@ -77,7 +77,7 @@ python3 update-specs.py
- commit new/changed `.xml` file to this repository;

> **_NOTE:_** If the resulting `.xml` file in not as expected, check/modify
the `asterix2json.py` script.
the `asterixjson2xml.py` script.

> **_NOTE:_** Do not manually edit converted `.xml` files if possible.
Expand Down
31 changes: 29 additions & 2 deletions asterix-specs-converter/asterixjson2xml.py
Expand Up @@ -5,6 +5,7 @@
import argparse
import json
import hashlib
from copy import copy
from itertools import chain, repeat

def getNumber(value):
Expand Down Expand Up @@ -102,7 +103,7 @@ def replaceOutput(s):
u'–': '-',
u'“': '',
u'”': '',
u'°': ' deg',
u'°': 'deg',
})

def tell(s):
Expand Down Expand Up @@ -304,6 +305,27 @@ def case2(val):

renderRule(content, case1, case2)

def get_bit_size(item):
"""Return bit size of a (spare) item."""
if item['spare']:
return item['length']
else:
return item['variation']['size']

def ungroup(item):
"""Convert group of items of known size to element"""
n = sum([get_bit_size(i) for i in item['variation']['items']])
result = copy(item)
result['variation'] = {
'rule': {
'content': {'type': 'Raw'},
'type': 'ContextFree',
},
'size': n,
'type': 'Element',
}
return result

class Variation(object):

@staticmethod
Expand All @@ -324,7 +346,12 @@ def create(parent, item):
if vt == 'Extended':
n1 = variation['first']
n2 = variation['extents']
items = variation['items']
items = []
for i in variation['items']:
if i.get('variation') is not None:
if i['variation']['type'] == 'Group':
i = ungroup(i)
items.append(i)
return Variable(parent, item, n1, n2, items)

if vt == 'Repetitive':
Expand Down
2 changes: 1 addition & 1 deletion asterix-specs-converter/specs/asterix_cat001_1_2.xml
Expand Up @@ -8,7 +8,7 @@
Do not edit this file!
This file is auto-generated from json specs file.
sha1sum of concatenated json input(s): 9ca74855641a0468d6c35a57a5bdd06c2dec4cb0
sha1sum of concatenated json input(s): 42d255f438a9c4fce818839ae6b4927d380e4200
See asterix-specs-converter/README.md for details.
-->
Expand Down
2 changes: 1 addition & 1 deletion asterix-specs-converter/specs/asterix_cat001_1_3.xml
Expand Up @@ -8,7 +8,7 @@
Do not edit this file!
This file is auto-generated from json specs file.
sha1sum of concatenated json input(s): 80c9cef3b90478b73c20f88a2ccd34540d0a6351
sha1sum of concatenated json input(s): 817a9cc056850f867a774fa1d794e09133877d55
See asterix-specs-converter/README.md for details.
-->
Expand Down

0 comments on commit 9f5a5ac

Please sign in to comment.