use of io.openems.common.types.FieldValue 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