Skip to content

Commit

Permalink
Update FMI headers and schema to 3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sommer committed Oct 26, 2023
1 parent 609b2ec commit 74cfa9c
Show file tree
Hide file tree
Showing 6 changed files with 4,187 additions and 3,036 deletions.
7 changes: 7 additions & 0 deletions fmusim/FMIModelDescription.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@

#include "structured_variable_name.tab.h"

// to regenerate run
//
// python xsdflatten.py fmi3ModelDescription.xsd > fmi3Merged.xsd
//
// and
//
// xxd -i xxd -i fmi3Merged.xsd > fmi3schema.h
#include "fmi1schema.h"
#include "fmi2schema.h"
#include "fmi3schema.h"
Expand Down
7,138 changes: 4,107 additions & 3,031 deletions fmusim/fmi3schema.h

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions include/fmi3FunctionTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This header file defines the data and function types of FMI 3.0.
It must be used when compiling an FMU or an FMI importer.
Copyright (C) 2011 MODELISAR consortium,
2012-2022 Modelica Association Project "FMI"
2012-2023 Modelica Association Project "FMI"
All rights reserved.
This file is licensed by the copyright holders under the 2-Clause BSD License
Expand Down Expand Up @@ -103,8 +103,8 @@ typedef void (*fmi3IntermediateUpdateCallback) (
/* end::CallbackIntermediateUpdate[] */

/* tag::CallbackPreemptionLock[] */
typedef void (*fmi3LockPreemptionCallback) (void);
typedef void (*fmi3UnlockPreemptionCallback) (void);
typedef void (*fmi3LockPreemptionCallback) ();
typedef void (*fmi3UnlockPreemptionCallback) ();
/* end::CallbackPreemptionLock[] */

/* Define fmi3 function pointer types to simplify dynamic loading */
Expand Down
2 changes: 1 addition & 1 deletion include/fmi3Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static link library. For FMUs compiled in a DLL/sharedObject, the "actual" funct
names are used and "FMI3_FUNCTION_PREFIX" must not be defined.
Copyright (C) 2008-2011 MODELISAR consortium,
2012-2022 Modelica Association Project "FMI"
2012-2023 Modelica Association Project "FMI"
All rights reserved.
This file is licensed by the copyright holders under the 2-Clause BSD License
Expand Down
2 changes: 1 addition & 1 deletion include/fmi3PlatformTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This header file defines the data types of FMI 3.0.
It must be used by both FMU and FMI master.
Copyright (C) 2008-2011 MODELISAR consortium,
2012-2022 Modelica Association Project "FMI"
2012-2023 Modelica Association Project "FMI"
All rights reserved.
This file is licensed by the copyright holders under the 2-Clause BSD License
Expand Down
68 changes: 68 additions & 0 deletions xsdflatten.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python

""" Adapted from https://github.com/esunder/xsdflatten """

import sys
import re
import copy
from lxml import etree


def get_includes_from_file(filename):
pattern = re.compile('(<xs:include schemaLocation)')
lines = [line.strip() for line in open(filename).readlines()]
includes = [line.split('=')[1].split('"')[1] for line in lines if pattern.match(line)]

# sanity check
for inc in includes:
if not inc.endswith('.xsd'):
pass #print 'There is a problem with include %s in file %s' % (inc, filename)

return includes


def get_includes_recurse(filename, include_set):
includes = get_includes_from_file(filename)
include_set.update(includes)
for inc in includes:
get_includes_recurse(inc, include_set)


def get_xml_tree_from_file(filename):
tree = etree.parse(filename)
return tree.getroot()


def remove_includes(root):
# Find and remove the includes
includes = root.findall('xs:include', root.nsmap)
for inc in includes:
root.remove(inc)
return root


def flatten_file(filename):
include_set = set()
get_includes_recurse(filename, include_set)

# Get the main document
root = get_xml_tree_from_file(filename)
root = remove_includes(root)

# Merge in the elements of the includes
for inc_file in include_set:
inc_root = get_xml_tree_from_file(inc_file)
inc_root = remove_includes(inc_root)
root.append(etree.Comment('Imported from %s' % inc_file))
for child in inc_root:
root.append(copy.deepcopy(child))

print(etree.tostring(root, pretty_print=True).decode('utf-8'))


def main(filename):
flatten_file(filename)


if __name__ == "__main__":
main(sys.argv[1])

0 comments on commit 74cfa9c

Please sign in to comment.