use of io.openems.api.channel.Channel in project openems by OpenEMS.
the class ModbusTcpApiController method updateChannelMapping.
protected void updateChannelMapping(Optional<JsonObject> jMappingOpt) {
processImage.clearMapping();
ThingRepository thingRepository = ThingRepository.getInstance();
if (jMappingOpt.isPresent()) {
JsonObject jMapping = jMappingOpt.get();
for (Entry<String, JsonElement> entry : jMapping.entrySet()) {
try {
int ref = Integer.parseInt(entry.getKey());
ChannelAddress channelAddress = ChannelAddress.fromString(JsonUtils.getAsString(entry.getValue()));
Optional<ChannelDoc> channelDocOpt = thingRepository.getChannelDoc(channelAddress);
if (channelDocOpt.isPresent()) {
processImage.addMapping(ref, channelAddress, channelDocOpt.get());
} else {
Optional<Channel> channelOpt = thingRepository.getChannel(channelAddress);
if (channelOpt.isPresent()) {
throw new OpenemsException("ChannelDoc for channel [" + channelAddress + "] is not available.");
} else {
throw new OpenemsException("Channel [" + channelAddress + "] does not exist.");
}
}
} catch (Exception e) {
log.error("Unable to add channel mapping: " + e.getMessage());
}
}
}
}
Aggregations