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