|
| 1 | +/* Node type: Functional Mock-up unit. |
| 2 | + * |
| 3 | + * Author: Jitpanu Maneeratpongsuk <jitpanu.maneeratpongsuk@rwth-aachen.de> |
| 4 | + * SPDX-FileCopyrightText: 2025 Institute for Automation of Complex Power Systems, RWTH Aachen University |
| 5 | + * SPDX-License-Identifier: Apache-2.0 |
| 6 | + */ |
| 7 | +#pragma once |
| 8 | + |
| 9 | +#include <string> |
| 10 | +#include <vector> |
| 11 | + |
| 12 | +#include <fmilib.h> |
| 13 | + |
| 14 | +#include <villas/format.hpp> |
| 15 | +#include <villas/node.hpp> |
| 16 | + |
| 17 | +namespace villas { |
| 18 | +namespace node { |
| 19 | + |
| 20 | +// Forward declarations |
| 21 | +struct Sample; |
| 22 | + |
| 23 | +class FmuNode : public Node { |
| 24 | +protected: |
| 25 | + int parse(json_t *json) override; |
| 26 | + |
| 27 | + int _read(struct Sample *smps[], unsigned cnt) override; |
| 28 | + int _write(struct Sample *smps[], unsigned cnt) override; |
| 29 | + |
| 30 | + bool writingTurn = true; |
| 31 | + const char *path; |
| 32 | + const char *unpack_path; |
| 33 | + |
| 34 | + timespec ts; |
| 35 | + pthread_mutex_t mutex; |
| 36 | + pthread_cond_t cv; |
| 37 | + |
| 38 | + fmi3_import_t *fmu; |
| 39 | + jm_callbacks callbacks; |
| 40 | + fmi_import_context_t *context; |
| 41 | + |
| 42 | +public: |
| 43 | + FmuNode(const uuid_t &id = {}, const std::string &name = ""); |
| 44 | + struct fmu_signal { |
| 45 | + unsigned int ref = 0; |
| 46 | + fmi3_base_type_enu_t type = fmi3_base_type_enu_t::fmi3_base_type_float64; |
| 47 | + std::string name; |
| 48 | + }; |
| 49 | + |
| 50 | + std::vector<fmu_signal> signalIn; |
| 51 | + std::vector<fmu_signal> signalOut; |
| 52 | + |
| 53 | + int prepare() override; |
| 54 | + |
| 55 | + int check() override; |
| 56 | + |
| 57 | + int start() override; |
| 58 | + |
| 59 | + int stop() override; |
| 60 | + |
| 61 | + // ~FmuNode(); |
| 62 | + |
| 63 | +private: |
| 64 | + void parse_signal(json_t *json, bool in); |
| 65 | + double currentTime = 0; |
| 66 | + double stepSize = 0.1; |
| 67 | + double stopTime = 0; |
| 68 | + double startTime = 0; |
| 69 | + bool stopTimeDef = false; |
| 70 | + double nextTime = 0.0; |
| 71 | + void get_vr(const char *var_name, fmi3_value_reference_t &ref, |
| 72 | + fmi3_base_type_enu_t &type); |
| 73 | +}; |
| 74 | + |
| 75 | +} // namespace node |
| 76 | +} // namespace villas |
0 commit comments