Search in sources :

Example 1 with RoverWriteTable

use of me.retrodaredevil.solarthing.solar.renogy.rover.RoverWriteTable 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);
        }
    });
}
Also used : RoverModbusEnvironment(me.retrodaredevil.solarthing.actions.environment.RoverModbusEnvironment) ModbusRuntimeException(me.retrodaredevil.io.modbus.ModbusRuntimeException) RoverWriteTable(me.retrodaredevil.solarthing.solar.renogy.rover.RoverWriteTable)

Example 2 with RoverWriteTable

use of me.retrodaredevil.solarthing.solar.renogy.rover.RoverWriteTable 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);
        }
    });
}
Also used : RoverModbusEnvironment(me.retrodaredevil.solarthing.actions.environment.RoverModbusEnvironment) ModbusRuntimeException(me.retrodaredevil.io.modbus.ModbusRuntimeException) RoverWriteTable(me.retrodaredevil.solarthing.solar.renogy.rover.RoverWriteTable)

Example 3 with RoverWriteTable

use of me.retrodaredevil.solarthing.solar.renogy.rover.RoverWriteTable in project solarthing by wildmountainfarms.

the class RoverMain method doRoverProgram.

private static int doRoverProgram(RoverOption options, RoverProgramRunner runner, @Nullable RegisterCacheHandler registerCacheHandler) {
    IOConfig ioConfig = ConfigUtil.parseIOConfig(options.getIOBundleFile(), RoverReadTable.SERIAL_CONFIG);
    try (ReloadableIOBundle ioBundle = new ReloadableIOBundle(ioConfig::createIOBundle)) {
        ModbusSlaveBus modbus = new IOModbusSlaveBus(ioBundle, new RtuDataEncoder(2000, 20, 4));
        MutableAddressModbusSlave slave = new MutableAddressModbusSlave(options.getModbusAddress(), modbus);
        final RoverReadTable read;
        final Runnable reloadCache;
        if (registerCacheHandler != null) {
            ModbusCacheSlave modbusCacheSlave = new ModbusCacheSlave(slave);
            read = new RoverModbusSlaveRead(modbusCacheSlave);
            reloadCache = () -> registerCacheHandler.cacheRegisters(modbusCacheSlave);
        } else {
            read = new RoverModbusSlaveRead(slave);
            reloadCache = () -> {
            };
        }
        RoverWriteTable write = new RoverModbusSlaveWrite(slave);
        return runner.doProgram(slave, read, write, reloadCache, ioBundle::reload);
    } catch (Exception e) {
        LOGGER.error(SolarThingConstants.SUMMARY_MARKER, "(Fatal)Got exception!", e);
        return SolarThingConstants.EXIT_CODE_CRASH;
    }
}
Also used : RoverModbusSlaveRead(me.retrodaredevil.solarthing.solar.renogy.rover.modbus.RoverModbusSlaveRead) IOModbusSlaveBus(me.retrodaredevil.io.modbus.IOModbusSlaveBus) ModbusCacheSlave(me.retrodaredevil.solarthing.program.modbus.ModbusCacheSlave) IOConfig(me.retrodaredevil.solarthing.config.io.IOConfig) RoverReadTable(me.retrodaredevil.solarthing.solar.renogy.rover.RoverReadTable) MutableAddressModbusSlave(me.retrodaredevil.solarthing.program.modbus.MutableAddressModbusSlave) RtuDataEncoder(me.retrodaredevil.io.modbus.RtuDataEncoder) RoverModbusSlaveWrite(me.retrodaredevil.solarthing.solar.renogy.rover.modbus.RoverModbusSlaveWrite) ReloadableIOBundle(me.retrodaredevil.solarthing.io.ReloadableIOBundle) IOModbusSlaveBus(me.retrodaredevil.io.modbus.IOModbusSlaveBus) ModbusSlaveBus(me.retrodaredevil.io.modbus.ModbusSlaveBus) RoverWriteTable(me.retrodaredevil.solarthing.solar.renogy.rover.RoverWriteTable)

Example 4 with RoverWriteTable

use of me.retrodaredevil.solarthing.solar.renogy.rover.RoverWriteTable 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));
}
Also used : RoverModbusSlaveRead(me.retrodaredevil.solarthing.solar.renogy.rover.modbus.RoverModbusSlaveRead) NetCatServerHandler(me.retrodaredevil.solarthing.netcat.NetCatServerHandler) ModbusCacheSlave(me.retrodaredevil.solarthing.program.modbus.ModbusCacheSlave) IOException(java.io.IOException) RoverReadTable(me.retrodaredevil.solarthing.solar.renogy.rover.RoverReadTable) RoverPacketListUpdater(me.retrodaredevil.solarthing.program.receiver.RoverPacketListUpdater) DataRequesterResult(me.retrodaredevil.solarthing.config.request.DataRequesterResult) RoverModbusEnvironment(me.retrodaredevil.solarthing.actions.environment.RoverModbusEnvironment) ConnectionHandler(me.retrodaredevil.solarthing.netcat.ConnectionHandler) ModbusListUpdaterWrapper(me.retrodaredevil.solarthing.program.receiver.ModbusListUpdaterWrapper) RoverModbusSlaveWrite(me.retrodaredevil.solarthing.solar.renogy.rover.modbus.RoverModbusSlaveWrite) RoverWriteTable(me.retrodaredevil.solarthing.solar.renogy.rover.RoverWriteTable)

Aggregations

RoverWriteTable (me.retrodaredevil.solarthing.solar.renogy.rover.RoverWriteTable)4 RoverModbusEnvironment (me.retrodaredevil.solarthing.actions.environment.RoverModbusEnvironment)3 ModbusRuntimeException (me.retrodaredevil.io.modbus.ModbusRuntimeException)2 ModbusCacheSlave (me.retrodaredevil.solarthing.program.modbus.ModbusCacheSlave)2 RoverReadTable (me.retrodaredevil.solarthing.solar.renogy.rover.RoverReadTable)2 RoverModbusSlaveRead (me.retrodaredevil.solarthing.solar.renogy.rover.modbus.RoverModbusSlaveRead)2 RoverModbusSlaveWrite (me.retrodaredevil.solarthing.solar.renogy.rover.modbus.RoverModbusSlaveWrite)2 IOException (java.io.IOException)1 IOModbusSlaveBus (me.retrodaredevil.io.modbus.IOModbusSlaveBus)1 ModbusSlaveBus (me.retrodaredevil.io.modbus.ModbusSlaveBus)1 RtuDataEncoder (me.retrodaredevil.io.modbus.RtuDataEncoder)1 IOConfig (me.retrodaredevil.solarthing.config.io.IOConfig)1 DataRequesterResult (me.retrodaredevil.solarthing.config.request.DataRequesterResult)1 ReloadableIOBundle (me.retrodaredevil.solarthing.io.ReloadableIOBundle)1 ConnectionHandler (me.retrodaredevil.solarthing.netcat.ConnectionHandler)1 NetCatServerHandler (me.retrodaredevil.solarthing.netcat.NetCatServerHandler)1 MutableAddressModbusSlave (me.retrodaredevil.solarthing.program.modbus.MutableAddressModbusSlave)1 ModbusListUpdaterWrapper (me.retrodaredevil.solarthing.program.receiver.ModbusListUpdaterWrapper)1 RoverPacketListUpdater (me.retrodaredevil.solarthing.program.receiver.RoverPacketListUpdater)1