From 00fb0363ddfde11aecb9d2566186fb9b8e24fd7f Mon Sep 17 00:00:00 2001 From: Daniel Krebs Date: Mon, 4 Jun 2018 17:08:36 +0200 Subject: [PATCH] ips/switch: add more sanity checks for making connections --- fpga/lib/ips/switch.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/fpga/lib/ips/switch.cpp b/fpga/lib/ips/switch.cpp index bc30e27b4..bb0ba0cbc 100644 --- a/fpga/lib/ips/switch.cpp +++ b/fpga/lib/ips/switch.cpp @@ -73,9 +73,26 @@ bool AxiStreamSwitch::connectInternal(const std::string& portSlave, const std::string& portMaster) { + // check if slave port exists + try { + getSlavePort(portSlave); + } catch(const std::out_of_range&) { + logger->error("Switch doesn't have a slave port named '{}'", portSlave); + return false; + } + + // check if master port exists + try { + getMasterPort(portMaster); + } catch(const std::out_of_range&) { + logger->error("Switch doesn't have a master port named '{}'", portMaster); + return false; + } + if(portSlave.substr(0, 1) != "S" or portMaster.substr(0, 1) != "M") { - logger->error("sanity check failed"); + logger->error("sanity check failed: master {} slave {}", + portMaster, portSlave); return false; }