hcpxml2json: collapse all uid into one feature list
This commit is contained in:
1111
xml/SX65EX56CN.json
1111
xml/SX65EX56CN.json
File diff suppressed because it is too large
Load Diff
1418
xml/WM6HXF91NL.json
1418
xml/WM6HXF91NL.json
File diff suppressed because it is too large
Load Diff
@@ -24,11 +24,13 @@ features = {}
|
|||||||
errors = {}
|
errors = {}
|
||||||
enums = {}
|
enums = {}
|
||||||
|
|
||||||
# Features
|
# Features are all possible UIDs
|
||||||
for child in featuremapping[1]: #.iter('feature'):
|
for child in featuremapping[1]: #.iter('feature'):
|
||||||
uid = int(child.attrib["refUID"], 16)
|
uid = int(child.attrib["refUID"], 16)
|
||||||
name = child.text
|
name = child.text
|
||||||
features[uid] = name
|
features[uid] = {
|
||||||
|
"name": name,
|
||||||
|
}
|
||||||
|
|
||||||
# Errors
|
# Errors
|
||||||
for child in featuremapping[2]:
|
for child in featuremapping[2]:
|
||||||
@@ -52,33 +54,34 @@ for child in featuremapping[3]:
|
|||||||
|
|
||||||
#####################
|
#####################
|
||||||
#
|
#
|
||||||
# Parse the description file
|
# Parse the description file and collapse everything into a single
|
||||||
|
# list of UIDs
|
||||||
#
|
#
|
||||||
|
|
||||||
def parse_xml_list(entries):
|
def parse_xml_list(codes, entries):
|
||||||
parsed = {}
|
|
||||||
|
|
||||||
for el in entries:
|
for el in entries:
|
||||||
# not sure how to parse refCID and refDID
|
# not sure how to parse refCID and refDID
|
||||||
uid = int(el.attrib["uid"], 16)
|
uid = int(el.attrib["uid"], 16)
|
||||||
data = {
|
|
||||||
"name": features[uid],
|
if not uid in codes:
|
||||||
}
|
print("UID", uid, " not known!", file=sys.stderr)
|
||||||
|
|
||||||
|
data = codes[uid];
|
||||||
|
if "uid" in codes:
|
||||||
|
print("UID", uid, " used twice?", data, file=sys.stderr)
|
||||||
|
|
||||||
for key in el.attrib:
|
for key in el.attrib:
|
||||||
data[key] = el.attrib[key]
|
data[key] = el.attrib[key]
|
||||||
|
|
||||||
# clean up
|
# clean up later
|
||||||
del data["uid"]
|
#del data["uid"]
|
||||||
|
|
||||||
if "enumerationType" in el.attrib:
|
if "enumerationType" in el.attrib:
|
||||||
del data["enumerationType"]
|
del data["enumerationType"]
|
||||||
enum_id = int(el.attrib["enumerationType"], 16)
|
enum_id = int(el.attrib["enumerationType"], 16)
|
||||||
data["values"] = enums[enum_id]["values"]
|
data["values"] = enums[enum_id]["values"]
|
||||||
|
|
||||||
parsed[uid] = data
|
#codes[uid] = data
|
||||||
|
|
||||||
return parsed
|
|
||||||
|
|
||||||
def parse_machine_description(entries):
|
def parse_machine_description(entries):
|
||||||
description = {}
|
description = {}
|
||||||
@@ -90,14 +93,16 @@ def parse_machine_description(entries):
|
|||||||
|
|
||||||
return description
|
return description
|
||||||
|
|
||||||
|
for i in range(4,8):
|
||||||
|
parse_xml_list(features, description[i])
|
||||||
|
|
||||||
|
# remove the duplicate uid field
|
||||||
|
for uid in features:
|
||||||
|
if "uid" in features[uid]:
|
||||||
|
del features[uid]["uid"]
|
||||||
|
|
||||||
machine = {
|
machine = {
|
||||||
"description": parse_machine_description(description[3]),
|
"description": parse_machine_description(description[3]),
|
||||||
"status": parse_xml_list(description[4]),
|
|
||||||
"settings": parse_xml_list(description[5]),
|
|
||||||
"events": parse_xml_list(description[6]),
|
|
||||||
"commands": parse_xml_list(description[7]),
|
|
||||||
"options": parse_xml_list(description[8]),
|
|
||||||
"errors": errors,
|
|
||||||
"features": features,
|
"features": features,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user