Created
June 23, 2020 11:36
-
-
Save Cybso/5af4ff57b1392cd699bc6ab98f67813d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Exports group addresses from ETS Inside project. Usage: | |
python3 inside-export-ga.py path/to/project | |
""" | |
import sys | |
import json | |
import xml.etree.ElementTree as ET | |
# Mapping of DPST Datapoint Types | |
DPT_MAPPING = { | |
'DPT-1': 'int', | |
'DPT-2': 'int', | |
'DPT-3': 'uint', | |
'DPT-4': 'string', | |
'DPT-5': 'percent', | |
'DPT-6': 'percent', | |
'DPT-7': 'uint', | |
'DPT-8': 'percent', | |
'DPT-9': 'float', | |
'DPT-10': 'time', | |
'DPT-11': 'date', | |
'DPT-12': 'uint', | |
'DPT-13': 'int', | |
'DPT-14': 'float', | |
'DPT-15': 'hex', | |
'DPT-16': 'string', | |
'DPT-17': 'int', | |
'DPT-18': 'int', | |
'DPT-19': 'datetime', | |
'DPT-20': 'bits' | |
} | |
### | |
# See loadETSIMapping: GA | |
### | |
def loadETSIGroupAddresses(mapping, source): | |
tree = ET.parse(source) | |
root = tree.getroot() | |
for el in root.findall('.//GA'): | |
address = el.get('Address') | |
name = el.get('Name', '') | |
desc = el.get('Description', '') | |
datatype = el.get('DatapointType') | |
if not name or not address: | |
continue | |
# Convert address | |
address = int(address) | |
address = "%d/%d/%d" % ( | |
(address >> 11), | |
(address >> 8) & 0x07, | |
address & 0xff | |
) | |
if desc: | |
name = name + " (" + desc + ")" | |
if datatype: | |
if datatype.startswith('DPST-'): | |
# Remove subtype | |
dashPos = datatype[5:].find('-') | |
if dashPos > 0: | |
datatype = 'DPT-' + datatype[5:5+dashPos] | |
datatype = DPT_MAPPING.get(datatype, datatype) | |
mapping[address] = { | |
"address": address, | |
"name": name, | |
"type": datatype | |
} | |
if __name__ == "__main__": | |
mapping = {} | |
loadETSIGroupAddresses(mapping, sys.argv[1] + '/G') | |
print(json.dumps(mapping, indent=2, ensure_ascii=False)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment