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);
}
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);
}
}
}
}
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;
}
Aggregations