use of io.openems.common.types.ChannelEnum in project openems by OpenEMS.
the class FeneconPersistence method addChannelValueToQueue.
/**
* Add a channel value to the send queue
*
* @param channel
* @param valueOpt
*/
private void addChannelValueToQueue(Channel channel, Optional<?> valueOpt) {
// Ignore anything that is not a ReadChannel
if (!(channel instanceof ReadChannel<?>)) {
return;
}
ReadChannel<?> readChannel = (ReadChannel<?>) channel;
// Ignore channels that shall not be persisted
if (readChannel.isDoNotPersist()) {
return;
}
// Read and format value from channel
FieldValue<?> fieldValue;
if (!valueOpt.isPresent()) {
fieldValue = new NullFieldValue();
} else {
Object value = valueOpt.get();
if (value instanceof Number) {
fieldValue = new NumberFieldValue((Number) value);
} else if (value instanceof String) {
fieldValue = new StringFieldValue((String) value);
} else if (value instanceof Inet4Address) {
fieldValue = new StringFieldValue(((Inet4Address) value).getHostAddress());
} else if (value instanceof Boolean) {
fieldValue = new NumberFieldValue(((Boolean) value) ? 1 : 0);
} else if (value instanceof ChannelEnum) {
fieldValue = new NumberFieldValue(((ChannelEnum) value).getValue());
} else if (value instanceof DeviceNature || value instanceof JsonElement || value instanceof Map || value instanceof Set || value instanceof List || value instanceof ThingMap) {
// ignore
return;
} else {
log.warn("FENECON Persistence for value type [" + value.getClass().getName() + "] of channel [" + channel.address() + "] is not implemented.");
return;
}
}
// Add timestamp + value to queue
synchronized (queue) {
queue.put(readChannel.address(), fieldValue);
}
}
use of io.openems.common.types.ChannelEnum in project openems by OpenEMS.
the class InfluxdbPersistence method channelUpdated.
/*
* Methods
*/
/**
* Receives events for all {@link ReadChannel}s, excluding {@link ConfigChannel}s via the {@link Databus}.
*/
@Override
public void channelUpdated(Channel channel, Optional<?> newValue) {
if (!(channel instanceof ReadChannel<?>)) {
return;
}
ReadChannel<?> readChannel = (ReadChannel<?>) channel;
if (!newValue.isPresent()) {
return;
}
Object value = newValue.get();
String field = readChannel.address().toString();
FieldValue<?> fieldValue;
// TODO merge this with io.openems.backend.timedata.influx.addChannelToBuilder()
if (value instanceof Number) {
fieldValue = new NumberFieldValue(field, (Number) value);
} else if (value instanceof String) {
fieldValue = new StringFieldValue(field, (String) value);
} else if (value instanceof ChannelEnum) {
fieldValue = new NumberFieldValue(field, ((ChannelEnum) value).getValue());
} else {
return;
}
// Round time to Cycle-Time
int cycleTime = this.getCycleTime();
Long timestamp = System.currentTimeMillis() / cycleTime * cycleTime;
synchronized (queue) {
queue.put(timestamp, fieldValue);
}
}
Aggregations