void HardwareController::handleConfig(string section, std::unordered_map<string, string> settings) { if (section == "[hardware]") { HardwareOutputDevice* device = nullptr; if (settings["device"] == "") LOG(ERROR) << "No device definition in [hardware] section"; else if (settings["device"] == "DMX512SerialDevice") device = new DMX512SerialDevice(); else if (settings["device"] == "EnttecDMXProDevice") device = new EnttecDMXProDevice(); else if (settings["device"] == "VirtualOutputDevice") device = new VirtualOutputDevice(); if (device) { if (!device->configure(settings)) { LOG(ERROR) << "Failed to configure device: " << settings["device"]; delete device; }else{ LOG(INFO) << "New hardware device: " << settings["device"] << " with: " << device->getChannelCount() << " channels"; devices.push_back(device); } } }else if(section == "[channel]") { if (settings["channel"] == "" || settings["name"] == "") LOG(ERROR) << "Incorrect properties in [channel] section"; else{ channel_mapping[settings["name"]] = settings["channel"].toInt(); LOG(INFO) << "Channel #" << settings["channel"] << ": " << settings["name"]; } }else if(section == "[channels]") { for(std::pair<string, string> item : settings) { channel_mapping[item.first] = item.second.toInt(); LOG(INFO) << "Channel #" << item.second << ": " << item.first; } }else if(section == "[state]") { string condition = settings["condition"]; HardwareMappingState state; state.variable = condition; state.compare_operator = HardwareMappingState::Greater; state.compare_value = 0.0; state.channel_nr = -1; if (channel_mapping.find(settings["target"]) != channel_mapping.end()) state.channel_nr = channel_mapping[settings["target"]]; for(HardwareMappingState::EOperator compare_operator : {HardwareMappingState::Less, HardwareMappingState::Greater, HardwareMappingState::Equal, HardwareMappingState::NotEqual}) { string compare_string = "<"; switch(compare_operator) { case HardwareMappingState::Less: compare_string = "<"; break; case HardwareMappingState::Greater: compare_string = ">"; break; case HardwareMappingState::Equal: compare_string = "=="; break; case HardwareMappingState::NotEqual: compare_string = "!="; break; } if (condition.find(compare_string) > -1) { state.variable = condition.substr(0, condition.find(compare_string)).strip(); state.compare_operator = compare_operator; state.compare_value = condition.substr(condition.find(compare_string) + 1).strip().toFloat(); } } if (state.channel_nr < 0) { LOG(ERROR) << "Unknown target channel in hardware.ini: " << settings["target"]; }else{ state.effect = createEffect(settings); if (state.effect) { LOG(DEBUG) << "New hardware state: " << state.channel_nr << ":" << state.variable << " " << state.compare_operator << " " << state.compare_value; states.push_back(state); } } }else if(section == "[event]") { string trigger = settings["trigger"]; HardwareMappingEvent event; event.compare_operator = HardwareMappingEvent::Change; if (trigger.startswith("<")) { event.compare_operator = HardwareMappingEvent::Decrease; trigger = trigger.substr(1).strip(); } if (trigger.startswith(">")) { event.compare_operator = HardwareMappingEvent::Increase; trigger = trigger.substr(1).strip(); } event.trigger_variable = trigger; event.channel_nr = -1; event.runtime = settings["runtime"].toFloat(); event.triggered = false; event.previous_value = 0.0; if (channel_mapping.find(settings["target"]) != channel_mapping.end()) event.channel_nr = channel_mapping[settings["target"]]; if (event.channel_nr < 0) { LOG(ERROR) << "Unknown target channel in hardware.ini: " << settings["target"]; }else{ event.effect = createEffect(settings); if (event.effect) { LOG(DEBUG) << "New hardware event: " << event.channel_nr << ":" << event.trigger_variable << " " << event.compare_operator; events.push_back(event); } } }else{ LOG(ERROR) << "Unknown section in hardware.ini: " << section; } }
void HardwareController::handleConfig(string section, std::unordered_map<string, string>& settings) { if (section == "[hardware]") { HardwareOutputDevice* device = nullptr; if (settings["device"] == "") LOG(ERROR) << "No device definition in [hardware] section"; else if (settings["device"] == "DMX512SerialDevice") device = new DMX512SerialDevice(); else if (settings["device"] == "EnttecDMXProDevice") device = new EnttecDMXProDevice(); else if (settings["device"] == "VirtualOutputDevice") device = new VirtualOutputDevice(); else if (settings["device"] == "sACNDevice") device = new StreamingAcnDMXDevice(); if (device) { if (!device->configure(settings)) { LOG(ERROR) << "Failed to configure device: " << settings["device"]; delete device; }else{ LOG(INFO) << "New hardware device: " << settings["device"] << " with: " << device->getChannelCount() << " channels"; devices.push_back(device); } } }else if(section == "[channel]") { if (settings["channel"] == "" || settings["name"] == "") { LOG(ERROR) << "Incorrect properties in [channel] section"; } else { channel_mapping[settings["name"]].clear(); channel_mapping[settings["name"]].push_back((settings["channel"].toInt() - 1)); LOG(INFO) << "Channel #" << settings["channel"] << ": " << settings["name"]; } }else if(section == "[channels]") { for(std::pair<string, string> item : settings) { channel_mapping[item.first].clear(); for(string number : item.second.split(",")) { channel_mapping[item.first].push_back((number.strip().toInt() - 1)); LOG(INFO) << "Channel #" << item.second << ": " << number; } } }else if(section == "[state]") { if (channel_mapping.find(settings["target"]) == channel_mapping.end()) { LOG(ERROR) << "Unknown target channel in hardware.ini: " << settings["target"]; }else{ std::vector<int> channel_numbers = channel_mapping[settings["target"]]; for(unsigned int idx=0; idx<channel_numbers.size(); idx++) { std::unordered_map<string, string> per_channel_settings; for(std::pair<string, string> item : settings) { std::vector<string> values = item.second.split(","); if (values.size() > idx) per_channel_settings[item.first] = values[idx].strip(); else per_channel_settings[item.first] = values[values.size() - 1].strip(); } createNewHardwareMappingState(channel_numbers[idx], per_channel_settings); } } }else if(section == "[event]") { if (channel_mapping.find(settings["target"]) == channel_mapping.end()) { LOG(ERROR) << "Unknown target channel in hardware.ini: " << settings["target"]; }else{ std::vector<int> channel_numbers = channel_mapping[settings["target"]]; for(unsigned int idx=0; idx<channel_numbers.size(); idx++) { std::unordered_map<string, string> per_channel_settings; for(std::pair<string, string> item : settings) { std::vector<string> values = item.second.split(","); if (values.size() > idx) per_channel_settings[item.first] = values[idx]; else per_channel_settings[item.first] = values[values.size() - 1]; } createNewHardwareMappingEvent(channel_numbers[idx], per_channel_settings); } } }else{ LOG(ERROR) << "Unknown section in hardware.ini: " << section; } }