Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Merge pull request #6 from JTS22/main
Browse files Browse the repository at this point in the history
adapt to recent VILLASnode changes
  • Loading branch information
m-mirz authored Jan 21, 2022
2 parents 31d0e17 + bd5ff3b commit ee0deda
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion include/dpsim-villas/InterfaceVillas.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace DPsim {
protected:
//Villas node to send / receive data to / from
String mNodeConfig;
std::unique_ptr<node::Node> mNode;
node::Node* mNode;

int mQueueLength;
int mSampleLength;
Expand Down
41 changes: 19 additions & 22 deletions src/InterfaceVillas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,19 @@ void InterfaceVillas::open(CPS::Logger::Log log) {
}
String nodeTypeString = json_string_value(nodeType);

node::NodeType* nodeTypeStruct = node::node_type_lookup(nodeTypeString);
if (nodeTypeStruct != nullptr) {
mNode = std::make_unique<node::Node>(nodeTypeStruct);
int ret = 0;
uuid_t fakeSuperNodeUUID;
uuid_generate_random(fakeSuperNodeUUID);
ret = mNode->parse(config, fakeSuperNodeUUID);
if (ret < 0) {
mLog->error("Error: Node in InterfaceVillas failed to parse config. Parse returned code {}", ret);
std::exit(1);
}
ret = mNode->check();
if (ret < 0) {
mLog->error("Error: Node in InterfaceVillas failed check. Check returned code {}", ret);
std::exit(1);
}
} else {
mLog->error("Error: NodeType {} is not known to VILLASnode!", nodeTypeString);
mNode = node::NodeFactory::make(nodeTypeString);

int ret = 0;
uuid_t fakeSuperNodeUUID;
uuid_generate_random(fakeSuperNodeUUID);
ret = mNode->parse(config, fakeSuperNodeUUID);
if (ret < 0) {
mLog->error("Error: Node in InterfaceVillas failed to parse config. Parse returned code {}", ret);
std::exit(1);
}
ret = mNode->check();
if (ret < 0) {
mLog->error("Error: Node in InterfaceVillas failed check. Check returned code {}", ret);
std::exit(1);
}

Expand Down Expand Up @@ -114,9 +109,7 @@ void InterfaceVillas::prepareNode() {
std::exit(1);
}

ret = node::node_type_start(mNode->getType(), nullptr); //We have no SuperNode, so just hope type_start doesnt use it...
if (ret)
throw RuntimeError("Failed to start node-type: {}", *mNode->getType());
mNode->getFactory()->start(nullptr); //We have no SuperNode, so just hope type_start doesnt use it...

ret = mNode->start();
if (ret < 0) {
Expand Down Expand Up @@ -167,6 +160,10 @@ void InterfaceVillas::close() {
mLog->error("Error: failed to destroy SamplePool in InterfaceVillas. pool_destroy returned code {}", ret);
std::exit(1);
}

mNode->getFactory()->stop();

delete mNode;
}

void InterfaceVillas::readValues(bool blocking) {
Expand Down Expand Up @@ -257,4 +254,4 @@ void InterfaceVillas::initVillas() {
throw RuntimeError("Error: VillasNode failed to initialize memory system");

villas::kernel::rt::init(villasPriority, villasAffinity);
}
}
2 changes: 1 addition & 1 deletion src/pybind-dpsim-villas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PyInterfaceShmem : public DPsim::InterfaceShmem {

auto signal = py::dict(
"name"_a = s->name,
"type"_a = node::signal_type_to_str(s->type)
"type"_a = node::signalTypeToString(s->type)
);

if (!s->unit.empty()) {
Expand Down

0 comments on commit ee0deda

Please sign in to comment.