use of me.retrodaredevil.solarthing.packets.identification.IdentifierFragment in project solarthing by wildmountainfarms.
the class DefaultIdentificationCacheDataPacket method putOnMap.
private static <T extends IdentificationCacheData> void putOnMap(Map<IdentifierFragment, T> map, List<IdentificationCacheNode<T>> list) {
for (IdentificationCacheNode<T> node : list) {
IdentifierFragment identifierFragment = IdentifierFragment.create(node.getFragmentId(), node.getData().getIdentifier());
T currentData = map.get(identifierFragment);
if (currentData != null) {
@SuppressWarnings("unchecked") T data = (T) currentData.combine(node.getData());
map.put(identifierFragment, data);
} else {
map.put(identifierFragment, node.getData());
}
}
}
use of me.retrodaredevil.solarthing.packets.identification.IdentifierFragment in project solarthing by wildmountainfarms.
the class MXFloatModeStuckEvent method run.
@Override
public void run(MessageSender sender, FragmentedPacketGroup previous, FragmentedPacketGroup current) {
for (Packet previousPacket : previous.getPackets()) {
if (previousPacket instanceof MXStatusPacket) {
MXStatusPacket previousMX = (MXStatusPacket) previousPacket;
KnownIdentifierFragment<OutbackIdentifier> identifierFragment = IdentifierFragment.create(previous.getFragmentId(previousPacket), previousMX.getIdentifier());
MXStatusPacket currentMX = null;
for (Packet currentPacket : current.getPackets()) {
if (currentPacket instanceof Identifiable) {
IdentifierFragment currentIdentifierFragment = IdentifierFragment.create(current.getFragmentId(currentPacket), ((Identifiable) currentPacket).getIdentifier());
if (identifierFragment.equals(currentIdentifierFragment)) {
currentMX = (MXStatusPacket) currentPacket;
}
}
}
if (currentMX == null) {
continue;
}
if (currentMX.isNewDay(previousMX)) {
enabledMap.put(identifierFragment, true);
}
if (enabledMap.getOrDefault(identifierFragment, false)) {
ChargerMode mode = currentMX.getChargingMode();
if (mode == ChargerMode.FLOAT) {
doAlert(sender, identifierFragment);
} else if (mode != ChargerMode.SILENT) {
enabledMap.put(identifierFragment, false);
LOGGER.debug("Disabling " + identifierFragment + " because mode is " + mode);
}
}
}
}
}
use of me.retrodaredevil.solarthing.packets.identification.IdentifierFragment in project solarthing by wildmountainfarms.
the class AccumulationUtil method mapPackets.
@SuppressWarnings("unchecked")
@Contract(pure = true)
public static <T extends Identifiable> Map<IdentifierFragment, List<TimestampedPacket<T>>> mapPackets(Class<T> clazz, List<? extends FragmentedPacketGroup> packetGroups) {
Map<IdentifierFragment, List<TimestampedPacket<T>>> packetMap = new HashMap<>();
for (FragmentedPacketGroup packetGroup : packetGroups) {
for (Packet packet : packetGroup.getPackets()) {
if (clazz.isInstance(packet)) {
int fragmentId = packetGroup.getFragmentId(packet);
T t = (T) packet;
IdentifierFragment identifierFragment = IdentifierFragment.create(fragmentId, t.getIdentifier());
List<TimestampedPacket<T>> packetList = packetMap.computeIfAbsent(identifierFragment, k -> new ArrayList<>());
long dateMillis = packetGroup.getDateMillisOrKnown(packet);
packetList.add(new TimestampedPacket<>(t, dateMillis));
}
}
}
return packetMap;
}
Aggregations