use of io.openems.common.types.NumberFieldValue 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.NumberFieldValue in project openems by OpenEMS.
the class DefaultMessages method timestampedData.
/**
* <pre>
* {
* timedata: {
* timestamp (Long): {
* channel: String,
* value: String | Number
* }
* }
* }
* </pre>
*
* @param token
* @return
*/
public static JsonObject timestampedData(long timestamp, HashMap<ChannelAddress, FieldValue<?>> queue) {
JsonObject jTimestamp = new JsonObject();
for (Entry<ChannelAddress, FieldValue<?>> entry : queue.entrySet()) {
String address = entry.getKey().toString();
FieldValue<?> fieldValue = entry.getValue();
if (fieldValue instanceof NumberFieldValue) {
jTimestamp.addProperty(address, ((NumberFieldValue) fieldValue).value);
} else if (fieldValue instanceof StringFieldValue) {
jTimestamp.addProperty(address, ((StringFieldValue) fieldValue).value);
}
}
JsonObject jTimedata = new JsonObject();
jTimedata.add(String.valueOf(timestamp), jTimestamp);
JsonObject j = new JsonObject();
j.add("timedata", jTimedata);
return j;
}
Aggregations