Skip to content
Snippets Groups Projects
Commit 2dc2492a authored by Karol Krizka's avatar Karol Krizka
Browse files

Remove EquipConf::autoconfigure.

parent 3dccc449
No related branches found
No related tags found
No related merge requests found
......@@ -29,21 +29,17 @@ EquipConf::EquipConf(const json& hardwareConfig)
setHardwareConfig(hardwareConfig);
}
bool EquipConf::setHardwareConfig(const std::string& hardwareConfigFile)
void EquipConf::setHardwareConfig(const std::string& hardwareConfigFile)
{
//load JSON object from file
std::ifstream i(hardwareConfigFile);
i >> m_hardwareConfig;
//determine missing parameters, if any and requested
return autoConfigure();
}
bool EquipConf::setHardwareConfig(const json& hardwareConfig)
void EquipConf::setHardwareConfig(const json& hardwareConfig)
{
//store JSON config file
m_hardwareConfig = hardwareConfig;
//determine missing parameters, if any and requested
return autoConfigure();
}
json EquipConf::getDeviceConf(const std::string& label)
......@@ -68,112 +64,11 @@ json EquipConf::getChannelConf(const std::string& label)
// General private
////////////////////
bool EquipConf::autoConfigure()
{
//check for missing configuration
//
// version field required
if (not m_hardwareConfig.contains("version")) {
std::cerr << "mandatory field 'version' missing from input configuration." << std::endl;
return false;
}
// check and store if autoconfiguration is enabled
bool autoconfigure(false);
if (m_hardwareConfig.contains("options")) {
if (m_hardwareConfig["options"].contains("autoconfigure")) {
autoconfigure = m_hardwareConfig["options"]["autoconfigure"];
}
}
m_hardwareConfig["options"]["autoconfigure"] = autoconfigure;
//
// Extract devices
//
// check hardware section exists
if (not m_hardwareConfig.contains("devices")) {
std::cerr << "mandatory field 'hardware' missing from input configuration." << std::endl;
return false;
}
// check mandatory device properties and transform if needed
for (auto& hw : m_hardwareConfig["devices"].items()) {
//check hw type
if (not hw.value().contains("hw-type")) {
std::cerr << "Missing required hardware type for: " << hw.key()
<< ". Ignoring" << std::endl;
continue;
}
std::string tmp_toLower = hw.value()["hw-type"];
std::transform(tmp_toLower.begin(), tmp_toLower.end(), tmp_toLower.begin(), ::tolower);
hw.value()["tw-type"] = tmp_toLower;
}
// loop over hardware and auto-configure it, if requested
//
bool anyFailure=false;
if (m_hardwareConfig["options"]["autoconfigure"]) {
for (auto& hw : m_hardwareConfig["devices"]) {
if (hw["hw-type"] == "ps") {
//call specific PS auto-configuration
anyFailure = anyFailure or autoConfigurePS(hw);
} else {
anyFailure = true;
std::cerr << "Unrecognized device type (" << hw["hw-type"]
<< ") for device: " << hw["label"] << std::endl;
continue;
}
if (anyFailure) continue;
}
} // autoconfiguration
//
// Extract channels
//
if (m_hardwareConfig.contains("channels"))
{ // check channels section exists
// check mandatory device properties and transform if needed
for (auto& ch : m_hardwareConfig["channels"].items())
{
//check hw-type
if (not ch.value().contains("hw-type")) {
std::cerr << "Missing required hw-type for: " << ch.key()
<< ". Ignoring" << std::endl;
continue;
}
//check power-supply
if (not ch.value().contains("device")) {
std::cerr << "Missing required device for: " << ch.key()
<< ". Ignoring" << std::endl;
continue;
}
//check channel
if (not ch.value().contains("channel")) {
std::cerr << "Missing required channel for: " << ch.key()
<< ". Ignoring" << std::endl;
continue;
}
}
}
return (not anyFailure);
}
////////////////////
// Power-Supply
////////////////////
bool EquipConf::autoConfigurePS(json device)
{
//if port is missing, scan usb first
//... @TODO: device discovery
std::cerr << "Autoconfiguration of PowerSupply requested. Not yet implemented." << std::endl;
return false;
}
std::shared_ptr<IPowerSupply> EquipConf::getPowerSupply(const std::string& name)
{
//first check if an object with the same name/type is already available (was already instantiated)
......
......@@ -40,12 +40,12 @@ public:
/** Set input hardware list file
* @param hardwareConfigFile input JSON file with list of hardware resrouces and options
*/
bool setHardwareConfig(const std::string& hardwareConfigFile);
void setHardwareConfig(const std::string& hardwareConfigFile);
/** Set input hardware list file
* @param hardwareConfig input JSON object with list of hardware resrouces and options
*/
bool setHardwareConfig(const json& hardwareConfig);
void setHardwareConfig(const json& hardwareConfig);
/** Get device JSON configuration
@param label device name
......@@ -98,17 +98,6 @@ private:
/// Stored handles of PowerSupplyChannel pointers created
std::unordered_map<std::string, std::shared_ptr<PowerSupplyChannel>> m_listPowerSupplyChannel;
/** Determine missing configuration of connected hardware, if possible.
Can as well perform some minimal validation of the input.
@return true if successful
*/
bool autoConfigure();
/** Auto-configuration for Power Supplies
* @param hw JSON hardware configuration for this device
*/
bool autoConfigurePS(json device);
};
#endif
......@@ -2,7 +2,6 @@
"version": "1.0",
"options" : {
"autoconfigure": false
},
"devices": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment