Search in sources :

Example 1 with DocumentedPacket

use of me.retrodaredevil.solarthing.packets.DocumentedPacket in project solarthing by wildmountainfarms.

the class SimplePacketGroupParser method parse.

@NotNull
public PacketGroup parse(ObjectNode objectNode) throws PacketParseException {
    JsonNode dateMillisNode = objectNode.get("dateMillis");
    if (dateMillisNode == null) {
        throw new PacketParseException("'dateMillis' does not exist for objectNode=" + objectNode);
    }
    if (!dateMillisNode.isNumber()) {
        throw new PacketParseException("'dateMillis' is not a number! dateMillisNode=" + dateMillisNode);
    }
    long dateMillis = dateMillisNode.asLong();
    JsonNode packetsNode = objectNode.get("packets");
    if (packetsNode == null) {
        throw new PacketParseException("'packets' does not exist for objectNode=" + objectNode);
    }
    if (!packetsNode.isArray()) {
        throw new PacketParseException("'packets' is not an array! packetsNode=" + packetsNode);
    }
    List<Packet> packetList = new ArrayList<>();
    for (JsonNode jsonPacket : packetsNode) {
        DocumentedPacket packet = null;
        try {
            packet = mapper.convertValue(jsonPacket, DocumentedPacket.class);
        } catch (IllegalArgumentException ex) {
            errorHandler.handleError(ex);
        }
        if (packet != null) {
            packetList.add(packet);
        }
    }
    return PacketGroups.createPacketGroup(packetList, dateMillis);
}
Also used : Packet(me.retrodaredevil.solarthing.packets.Packet) DocumentedPacket(me.retrodaredevil.solarthing.packets.DocumentedPacket) DocumentedPacket(me.retrodaredevil.solarthing.packets.DocumentedPacket) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) NotNull(me.retrodaredevil.solarthing.annotations.NotNull)

Example 2 with DocumentedPacket

use of me.retrodaredevil.solarthing.packets.DocumentedPacket in project solarthing by wildmountainfarms.

the class FXStatusListUpdater method receive.

@Override
public void receive(List<Packet> packets) {
    long now = System.currentTimeMillis();
    long timeId = timeIdentifier.getTimeId(now);
    final Long lastTimeId = this.lastTimeId;
    this.lastTimeId = timeId;
    if (lastTimeId != null && lastTimeId != timeId) {
        fxMap.clear();
    }
    for (Packet packet : new ArrayList<>(packets)) {
        if (packet instanceof DocumentedPacket) {
            DocumentedPacketType packetType = ((DocumentedPacket) packet).getPacketType();
            if (packetType == SolarStatusPacketType.FX_STATUS) {
                FXStatusPacket fx = (FXStatusPacket) packet;
                Identifier identifier = fx.getIdentifier();
                FXListUpdater updater = fxMap.get(identifier);
                if (updater == null) {
                    updater = new FXListUpdater();
                    fxMap.put(identifier, updater);
                }
                updater.update(now, packets, fx);
            }
        }
    }
}
Also used : Packet(me.retrodaredevil.solarthing.packets.Packet) ImmutableDailyFXPacket(me.retrodaredevil.solarthing.solar.outback.fx.extra.ImmutableDailyFXPacket) DailyFXPacket(me.retrodaredevil.solarthing.solar.outback.fx.extra.DailyFXPacket) DocumentedPacket(me.retrodaredevil.solarthing.packets.DocumentedPacket) FXStatusPacket(me.retrodaredevil.solarthing.solar.outback.fx.FXStatusPacket) FXStatusPacket(me.retrodaredevil.solarthing.solar.outback.fx.FXStatusPacket) TimeIdentifier(me.retrodaredevil.solarthing.util.time.TimeIdentifier) Identifier(me.retrodaredevil.solarthing.packets.identification.Identifier) DocumentedPacket(me.retrodaredevil.solarthing.packets.DocumentedPacket) DocumentedPacketType(me.retrodaredevil.solarthing.packets.DocumentedPacketType)

Example 3 with DocumentedPacket

use of me.retrodaredevil.solarthing.packets.DocumentedPacket in project solarthing by wildmountainfarms.

the class PointUtil method getTags.

public static Map<String, String> getTags(Packet packet) {
    Map<String, String> r = new HashMap<>();
    if (packet instanceof Identifiable) {
        Identifier identifier = ((Identifiable) packet).getIdentifier();
        r.put("identifier", identifier.getRepresentation());
        if (identifier instanceof SupplementaryIdentifier) {
            SupplementaryIdentifier supplementaryIdentifier = (SupplementaryIdentifier) identifier;
            r.put("identifier_supplementaryTo", supplementaryIdentifier.getSupplementaryTo().getRepresentation());
        }
    }
    if (packet instanceof DocumentedPacket) {
        DocumentedPacket documentedPacket = (DocumentedPacket) packet;
        DocumentedPacketType type = documentedPacket.getPacketType();
        r.put("packetType", type.toString());
    }
    return r;
}
Also used : Identifier(me.retrodaredevil.solarthing.packets.identification.Identifier) SupplementaryIdentifier(me.retrodaredevil.solarthing.packets.identification.SupplementaryIdentifier) DocumentedPacket(me.retrodaredevil.solarthing.packets.DocumentedPacket) SupplementaryIdentifier(me.retrodaredevil.solarthing.packets.identification.SupplementaryIdentifier) DocumentedPacketType(me.retrodaredevil.solarthing.packets.DocumentedPacketType) Identifiable(me.retrodaredevil.solarthing.packets.identification.Identifiable)

Aggregations

DocumentedPacket (me.retrodaredevil.solarthing.packets.DocumentedPacket)3 DocumentedPacketType (me.retrodaredevil.solarthing.packets.DocumentedPacketType)2 Packet (me.retrodaredevil.solarthing.packets.Packet)2 Identifier (me.retrodaredevil.solarthing.packets.identification.Identifier)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayList (java.util.ArrayList)1 NotNull (me.retrodaredevil.solarthing.annotations.NotNull)1 Identifiable (me.retrodaredevil.solarthing.packets.identification.Identifiable)1 SupplementaryIdentifier (me.retrodaredevil.solarthing.packets.identification.SupplementaryIdentifier)1 FXStatusPacket (me.retrodaredevil.solarthing.solar.outback.fx.FXStatusPacket)1 DailyFXPacket (me.retrodaredevil.solarthing.solar.outback.fx.extra.DailyFXPacket)1 ImmutableDailyFXPacket (me.retrodaredevil.solarthing.solar.outback.fx.extra.ImmutableDailyFXPacket)1 TimeIdentifier (me.retrodaredevil.solarthing.util.time.TimeIdentifier)1