How imaginus02/microfmu-library works
Project Type and Purpose
• This project is a specialized library that integrates FMU (Functional Mock-up Unit) simulation capabilities into MicroPython. Essentially, it provides a simulation engine written in C (the simulator in main.c) and wraps it as a module that can be compiled into MicroPython.
• The README indicates two primary target build environments: Unix (via a Makefile based on micropython.mk) and ESP32 (via a CMake file, micropython.cmake). Also, a helper script (parseFMU.sh) is used to unpack and process FMU files.
File Structure
• Top-level files: .gitignore, Makefile, README.md, micropython.cmake, and parseFMU.sh—these serve as general project configuration and build support.
• The “library” directory houses the core simulation code:
– “library/main.c” is the primary implementation of the simulator and MicroPython interfacing functions.
– “library/headers/” includes standard header files (fmi2FunctionTypes.h, fmi2Functions.h, fmi2TypesPlatform.h) that likely define FMU-related types and functions.
– “library/micropython.mk” is a build script module tailored for Unix compilation of MicroPython integration.
• The presence of both a Makefile and distinct build scripts (micropython.mk for Unix, micropython.cmake for ESP32) highlights a design intended to support multiple target platforms using different build systems.
Main Components to Illustrate
a. Build & Compilation Subsystem:
• Makefile: The main orchestrator for compilation and cleaning.
• Build Modules:
• micropython.mk for Unix builds.
• micropython.cmake for ESP32 builds.
• FMU Parsing: The parseFMU.sh script, which prepares the FMU files (by decompressing them and extracting content).
b. Core Simulation Engine:
• main.c: Implements the simulation logic and integrates with MicroPython to expose FMU simulation functionalities.
• FMU Standard Headers: The header files under library/headers defining FMU types and functions (crucial for standard compliance and interoperability).
c. MicroPython Integration:
• The mechanism by which the simulation engine is built into MicroPython (via the USER_C_MODULES mechanism in the build commands) to enable running simulations within the MicroPython environment.
Relationships and Data Flow
• Data Flow between the FMU Parser and the Simulation Engine: The parseFMU.sh script processes FMU files, which are then used by the simulation engine (main.c) to perform simulation tasks.
• Build Chain: The Makefile calls the appropriate build modules (either micropython.mk or micropython.cmake depending on target) to compile the simulation engine as a MicroPython module.
• Integration with MicroPython: The compiled simulator (including FMU functionality) is injected as a C module into the MicroPython environment, meaning there is a clear interface boundary between the core C simulation code and the MicroPython runtime.
Architectural Patterns and Design Principles
• Modular Design: The separation between FMU parsing, simulation engine, and MicroPython integration supports the modular design principle.
• Cross-Platform Compilation: By having separate build scripts and configuration files for Unix and ESP32, the design emphasizes portability and reusability.
• Standard Compliance: Including dedicated FMU header files indicates adherence to FMU standard interfaces.
Additional Details
• Optionally, add an external link or annotation noting that parts of the simulation engine are inspired or derived from the fmuSDK project.