use of me.retrodaredevil.solarthing.actions.environment.RoverModbusEnvironment in project solarthing by wildmountainfarms.
the class RoverBoostSetActionNode method createAction.
@Override
public Action createAction(ActionEnvironment actionEnvironment) {
RoverModbusEnvironment environment = actionEnvironment.getInjectEnvironment().get(RoverModbusEnvironment.class);
RoverWriteTable write = environment.getWrite();
return Actions.createRunOnce(() -> {
try {
if (boostVoltageRaw != null) {
write.setBoostChargingVoltageRaw(boostVoltageRaw);
}
if (boostTimeMinutes != null) {
write.setBoostChargingTimeMinutes(boostTimeMinutes);
}
LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "Successfully executed changed boost parameters.");
} catch (ModbusRuntimeException e) {
LOGGER.error("Unable to perform Modbus request", e);
}
});
}
use of me.retrodaredevil.solarthing.actions.environment.RoverModbusEnvironment in project solarthing by wildmountainfarms.
the class RoverLoadActionNode method createAction.
@Override
public Action createAction(ActionEnvironment actionEnvironment) {
RoverModbusEnvironment environment = actionEnvironment.getInjectEnvironment().get(RoverModbusEnvironment.class);
RoverWriteTable write = environment.getWrite();
return Actions.createRunOnce(() -> {
try {
write.setLoadWorkingMode(LoadWorkingMode.MANUAL);
write.setStreetLightStatus(on ? StreetLight.ON : StreetLight.OFF);
LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "Successfully executed load command. on: " + on);
} catch (ModbusRuntimeException e) {
LOGGER.error("Unable to perform Modbus request", e);
}
});
}
use of me.retrodaredevil.solarthing.actions.environment.RoverModbusEnvironment in project solarthing by wildmountainfarms.
the class RoverModbusRequester method create.
@Override
public DataRequesterResult create(RequestObject requestObject, SuccessReporter successReporter, ModbusSlave modbus) {
final RoverReadTable read;
final Runnable reloadCache;
if (bulkRequest) {
ModbusCacheSlave modbusCacheSlave = new ModbusCacheSlave(modbus);
read = new RoverModbusSlaveRead(modbusCacheSlave);
reloadCache = () -> cacheRegisters(modbusCacheSlave);
} else {
read = new RoverModbusSlaveRead(modbus);
reloadCache = () -> {
};
}
RoverWriteTable write = new RoverModbusSlaveWrite(modbus);
RoverModbusEnvironment roverModbusEnvironment = new RoverModbusEnvironment(read, write);
final NetCatServerHandler netCatServerHandler;
if (configurationServerConfig == null) {
netCatServerHandler = null;
} else {
try {
netCatServerHandler = new NetCatServerHandler(configurationServerConfig.getBindAddress(), configurationServerConfig.getPort());
} catch (IOException e) {
throw new RuntimeException("Could not create NetCatServerHandler", e);
}
}
return new DataRequesterResult(new ModbusListUpdaterWrapper(new RoverPacketListUpdater(number, read, write, netCatServerHandler == null ? null : new ConnectionHandler(netCatServerHandler)), reloadCache, successReporter, sendErrorPackets, "rover.error." + number), new AttachToCommandEnvironmentUpdater(Collections.singletonList(roverModbusEnvironment), attachToCommands::contains));
}
Aggregations