Search in sources :

Example 6 with PacketListReceiver

use of me.retrodaredevil.solarthing.packets.handling.PacketListReceiver in project solarthing by wildmountainfarms.

the class ModbusDataRequester method create.

@Override
public DataRequesterResult create(RequestObject requestObject) {
    ModbusRequester first = addressToModbusRequesterMap.values().stream().findFirst().orElseThrow(NoSuchElementException::new);
    IOConfig ioConfig = ConfigUtil.parseIOConfig(ioBundleFile, first.getDefaultSerialConfig());
    ReloadableIOBundle ioBundle = new ReloadableIOBundle(ioConfig::createIOBundle);
    ModbusSlaveBus modbus = new IOModbusSlaveBus(ioBundle, new RtuDataEncoder(rtuInitialTimeoutMillis, rtuEndTimeoutMillis, 4));
    ReloadIOSuccessReporterHandler reloadIOSuccessReporterHandler = new ReloadIOSuccessReporterHandler(ioBundle::reload);
    List<PacketListReceiver> packetListReceiverList = new ArrayList<>();
    List<EnvironmentUpdater> environmentUpdaterList = new ArrayList<>();
    for (Map.Entry<Integer, ModbusRequester> entry : addressToModbusRequesterMap.entrySet()) {
        int address = entry.getKey();
        ModbusRequester modbusRequester = entry.getValue();
        ModbusSlave slave = new ImmutableAddressModbusSlave(address, modbus);
        DataRequesterResult result = modbusRequester.create(requestObject, reloadIOSuccessReporterHandler.createReporter(), slave);
        packetListReceiverList.add(result.getStatusPacketListReceiver());
        environmentUpdaterList.add(result.getEnvironmentUpdater());
    }
    return new DataRequesterResult(new PacketListReceiverMultiplexer(packetListReceiverList), new EnvironmentUpdaterMultiplexer(environmentUpdaterList));
}
Also used : EnvironmentUpdaterMultiplexer(me.retrodaredevil.solarthing.actions.command.EnvironmentUpdaterMultiplexer) ArrayList(java.util.ArrayList) EnvironmentUpdater(me.retrodaredevil.solarthing.actions.command.EnvironmentUpdater) IOConfig(me.retrodaredevil.solarthing.config.io.IOConfig) DataRequesterResult(me.retrodaredevil.solarthing.config.request.DataRequesterResult) PacketListReceiverMultiplexer(me.retrodaredevil.solarthing.packets.handling.PacketListReceiverMultiplexer) PacketListReceiver(me.retrodaredevil.solarthing.packets.handling.PacketListReceiver) ReloadableIOBundle(me.retrodaredevil.solarthing.io.ReloadableIOBundle) Map(java.util.Map) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

PacketListReceiver (me.retrodaredevil.solarthing.packets.handling.PacketListReceiver)6 SolarThingConstants (me.retrodaredevil.solarthing.SolarThingConstants)3 EnvironmentUpdater (me.retrodaredevil.solarthing.actions.command.EnvironmentUpdater)3 EnvironmentUpdaterMultiplexer (me.retrodaredevil.solarthing.actions.command.EnvironmentUpdaterMultiplexer)3 DataRequesterResult (me.retrodaredevil.solarthing.config.request.DataRequesterResult)3 PacketListReceiverMultiplexer (me.retrodaredevil.solarthing.packets.handling.PacketListReceiverMultiplexer)3 ArgumentValidationException (com.lexicalscope.jewel.cli.ArgumentValidationException)2 Cli (com.lexicalscope.jewel.cli.Cli)2 CliFactory (com.lexicalscope.jewel.cli.CliFactory)2 HelpRequestedException (com.lexicalscope.jewel.cli.HelpRequestedException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 UtilityClass (me.retrodaredevil.solarthing.annotations.UtilityClass)2 AvailableCommandsListUpdater (me.retrodaredevil.solarthing.commands.packets.status.AvailableCommandsListUpdater)2 IOConfig (me.retrodaredevil.solarthing.config.io.IOConfig)2 DataRequester (me.retrodaredevil.solarthing.config.request.DataRequester)2 RequestObject (me.retrodaredevil.solarthing.config.request.RequestObject)2 ReloadableIOBundle (me.retrodaredevil.solarthing.io.ReloadableIOBundle)2 DataIdentifiablePacketListChecker (me.retrodaredevil.solarthing.misc.common.DataIdentifiablePacketListChecker)2 PacketCollectionIdGenerator (me.retrodaredevil.solarthing.packets.collection.PacketCollectionIdGenerator)2