use of io.openems.api.exception.ConfigException in project openems by OpenEMS.
the class Config method createConfigWorkingBackup.
private synchronized void createConfigWorkingBackup() {
try {
log.info("Create 'Working Backup' [" + configWorkingBackupFile.toString() + "]");
Files.copy(configFile, configWorkingBackupFile, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
ConfigException ex = new ConfigException("Unable to create 'Working Backup' [" + configWorkingBackupFile.toString() + "]");
log.error(ex.getMessage(), ex);
}
}
use of io.openems.api.exception.ConfigException in project openems by OpenEMS.
the class Config method createConfigLatestBackup.
private synchronized void createConfigLatestBackup() {
try {
log.info("Create 'Latest Backup' [" + configLatestBackupFile.toString() + "]");
Files.copy(configFile, configLatestBackupFile, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
ConfigException ex = new ConfigException("Unable to create 'Latest Backup' [" + configLatestBackupFile.toString() + "]");
log.error(ex.getMessage(), ex);
}
}
use of io.openems.api.exception.ConfigException in project openems by OpenEMS.
the class WagoFB method getConfig.
public static HashMap<String, List<String>> getConfig(Inet4Address ip) throws ConfigException {
if (configCache.containsKey(ip)) {
return configCache.get(ip);
} else {
HashMap<String, List<String>> channels = new HashMap<>();
String username = "admin";
String password = "wago";
int ftpPort = 21;
URL url;
Document doc;
try {
url = new URL("ftp://" + username + ":" + password + "@" + ip.getHostAddress() + ":" + ftpPort + "/etc/EA-config.xml;type=i");
URLConnection urlc = url.openConnection();
InputStream is = urlc.getInputStream();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
doc = dBuilder.parse(is);
doc.getDocumentElement().normalize();
} catch (IOException | SAXException | ParserConfigurationException e) {
throw new ConfigException(e.getMessage());
}
Node wagoNode = doc.getElementsByTagName("WAGO").item(0);
if (wagoNode != null) {
HashMap<String, Integer> moduleCounter = new HashMap<String, Integer>();
Node moduleNode = wagoNode.getFirstChild();
while (moduleNode != null) {
if (moduleNode.getNodeType() == Node.ELEMENT_NODE) {
NamedNodeMap moduleAttrs = moduleNode.getAttributes();
// String article = moduleAttrs.getNamedItem("ARTIKELNR").getNodeValue();
String moduletype = moduleAttrs.getNamedItem("MODULETYPE").getNodeValue();
if (!moduleCounter.containsKey(moduletype)) {
moduleCounter.put(moduletype, 0);
}
moduleCounter.replace(moduletype, moduleCounter.get(moduletype) + 1);
int index = 1;
Node channelNode = moduleNode.getFirstChild();
while (channelNode != null) {
if (channelNode.getNodeType() == Node.ELEMENT_NODE) {
NamedNodeMap channelAttrs = channelNode.getAttributes();
String channelType = channelAttrs.getNamedItem("CHANNELTYPE").getNodeValue();
if (!channels.containsKey(channelType)) {
channels.put(channelType, new ArrayList<String>());
}
String channelName = "";
switch(channelType) {
case "DO":
channelName = "DigitalOutput_" + moduleCounter.get(channelType) + "_" + index;
break;
case "DI":
channelName = "DigitalInput_" + moduleCounter.get(channelType) + "_" + index;
break;
default:
LoggerFactory.getLogger(WagoFB.class).debug("ChannelType: " + channelName + " nicht erkannt");
break;
}
channels.get(channelType).add(channelName);
index++;
}
channelNode = channelNode.getNextSibling();
}
}
moduleNode = moduleNode.getNextSibling();
}
}
configCache.put(ip, channels);
return channels;
}
}
use of io.openems.api.exception.ConfigException in project openems by OpenEMS.
the class FeneconPersistence method dispose.
@Override
protected void dispose() {
this.reconnectingWebsocket.dispose();
try {
Config config = Config.getInstance();
config.removeOnConfigUpdateListener(this.onConfigUpdate);
} catch (ConfigException e) {
log.error(e.getMessage());
}
}
use of io.openems.api.exception.ConfigException in project openems by OpenEMS.
the class KebaDevice method send.
/**
* Send UDP message to Keba EVCS
*
* @param s
* @throws IOException
* @throws ConfigException
* @throws InterruptedException
*/
protected void send(String s) throws OpenemsException {
Optional<Inet4Address> ipOpt = this.ip.valueOptional();
if (!ipOpt.isPresent()) {
throw new ConfigException("No IP address configured for Device[" + this.id() + "]");
} else {
Inet4Address ip = ipOpt.get();
byte[] raw = s.getBytes();
DatagramPacket packet = new DatagramPacket(raw, raw.length, ip, PORT);
DatagramSocket dSocket = null;
try {
dSocket = new DatagramSocket();
log.info("Sending message to KEBA [" + s + "]");
dSocket.send(packet);
} catch (SocketException e) {
throw new OpenemsException("Unable to open UDP socket for sending [" + s + "] to [" + ip.getHostAddress() + "]: " + e.getMessage(), e);
} catch (IOException e) {
throw new OpenemsException("Unable to send [" + s + "] UDP message to [" + ip.getHostAddress() + "]: " + e.getMessage());
} finally {
if (dSocket != null) {
dSocket.close();
}
}
}
}
Aggregations