Search in sources :

Example 1 with FieldValue

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;
}
Also used : StringFieldValue(io.openems.common.types.StringFieldValue) JsonObject(com.google.gson.JsonObject) ChannelAddress(io.openems.common.types.ChannelAddress) NumberFieldValue(io.openems.common.types.NumberFieldValue) NumberFieldValue(io.openems.common.types.NumberFieldValue) FieldValue(io.openems.common.types.FieldValue) StringFieldValue(io.openems.common.types.StringFieldValue)

Aggregations

JsonObject (com.google.gson.JsonObject)1 ChannelAddress (io.openems.common.types.ChannelAddress)1 FieldValue (io.openems.common.types.FieldValue)1 NumberFieldValue (io.openems.common.types.NumberFieldValue)1 StringFieldValue (io.openems.common.types.StringFieldValue)1