Search in sources :

Example 6 with IdentifierFragment

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());
        }
    }
}
Also used : IdentifierFragment(me.retrodaredevil.solarthing.packets.identification.IdentifierFragment)

Example 7 with IdentifierFragment

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);
                }
            }
        }
    }
}
Also used : Packet(me.retrodaredevil.solarthing.packets.Packet) MXStatusPacket(me.retrodaredevil.solarthing.solar.outback.mx.MXStatusPacket) KnownIdentifierFragment(me.retrodaredevil.solarthing.packets.identification.KnownIdentifierFragment) IdentifierFragment(me.retrodaredevil.solarthing.packets.identification.IdentifierFragment) MXStatusPacket(me.retrodaredevil.solarthing.solar.outback.mx.MXStatusPacket) ChargerMode(me.retrodaredevil.solarthing.solar.outback.mx.ChargerMode) OutbackIdentifier(me.retrodaredevil.solarthing.solar.outback.OutbackIdentifier) Identifiable(me.retrodaredevil.solarthing.packets.identification.Identifiable)

Example 8 with IdentifierFragment

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;
}
Also used : FragmentedPacketGroup(me.retrodaredevil.solarthing.packets.collection.FragmentedPacketGroup) Packet(me.retrodaredevil.solarthing.packets.Packet) TimestampedPacket(me.retrodaredevil.solarthing.packets.TimestampedPacket) HashMap(java.util.HashMap) IdentifierFragment(me.retrodaredevil.solarthing.packets.identification.IdentifierFragment) TimestampedPacket(me.retrodaredevil.solarthing.packets.TimestampedPacket) List(java.util.List) ArrayList(java.util.ArrayList) Contract(org.jetbrains.annotations.Contract)

Aggregations

IdentifierFragment (me.retrodaredevil.solarthing.packets.identification.IdentifierFragment)8 Packet (me.retrodaredevil.solarthing.packets.Packet)5 TimestampedPacket (me.retrodaredevil.solarthing.packets.TimestampedPacket)3 FragmentedPacketGroup (me.retrodaredevil.solarthing.packets.collection.FragmentedPacketGroup)3 Identifiable (me.retrodaredevil.solarthing.packets.identification.Identifiable)3 InstancePacketGroup (me.retrodaredevil.solarthing.packets.collection.InstancePacketGroup)2 DefaultIdentificationCacheDataPacket (me.retrodaredevil.solarthing.type.cache.packets.DefaultIdentificationCacheDataPacket)2 IdentificationCacheNode (me.retrodaredevil.solarthing.type.cache.packets.IdentificationCacheNode)2 Duration (java.time.Duration)1 Instant (java.time.Instant)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 TemperaturePacket (me.retrodaredevil.solarthing.misc.weather.TemperaturePacket)1 Identifier (me.retrodaredevil.solarthing.packets.identification.Identifier)1 KnownIdentifierFragment (me.retrodaredevil.solarthing.packets.identification.KnownIdentifierFragment)1 AddStatusParametersBuilder (me.retrodaredevil.solarthing.pvoutput.data.AddStatusParametersBuilder)1 PVCurrentAndVoltage (me.retrodaredevil.solarthing.solar.common.PVCurrentAndVoltage)1