use of me.retrodaredevil.io.modbus.ModbusRuntimeException in project solarthing by wildmountainfarms.
the class TracerLoadActionNode method createAction.
@Override
public Action createAction(ActionEnvironment actionEnvironment) {
TracerModbusEnvironment tracerModbusEnvironment = actionEnvironment.getInjectEnvironment().get(TracerModbusEnvironment.class);
TracerWriteTable write = tracerModbusEnvironment.getWrite();
return Actions.createRunOnce(() -> {
try {
write.setLoadControlMode(LoadControlMode.MANUAL_CONTROL);
write.setManualLoadControlOn(on);
LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "Successfully executed tracer load command. on: " + on);
} catch (ModbusRuntimeException e) {
LOGGER.error("Unable to perform tracer write Modbus request", e);
}
});
}
use of me.retrodaredevil.io.modbus.ModbusRuntimeException 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.io.modbus.ModbusRuntimeException 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.io.modbus.ModbusRuntimeException in project solarthing by wildmountainfarms.
the class ModbusListUpdaterWrapper method receive.
@Override
public void receive(List<Packet> packets) {
final long startTimeNanos = System.nanoTime();
try {
reloadCache.run();
packetListReceiver.receive(packets);
} catch (ModbusRuntimeException e) {
LOGGER.error("Modbus exception", e);
if (isSendErrorPackets) {
LOGGER.debug("Sending error packets");
packets.add(new ImmutableExceptionErrorPacket(e.getClass().getName(), e.getMessage(), MODBUS_RUNTIME_EXCEPTION_CATCH_LOCATION_IDENTIFIER, errorIdentifierString));
}
boolean isTimeout = false;
if (e.getCause() instanceof NotInitializedIOException) {
isTimeout = true;
}
if (e instanceof ModbusTimeoutException) {
isTimeout = true;
// These messages will hopefully help people with problems fix it faster.
if (hasBeenSuccessful) {
LOGGER.info("\n\nHey! We noticed you got a ModbusTimeoutException after getting this to work.\n" + "This is likely a fluke and hopefully this message isn't printed a bunch of times. If it is not a fluke, you may want to check your cable.\n");
} else {
LOGGER.info("\n\nHey! We noticed you got a ModbusTimeoutException.\n" + "This is likely a problem with your cable. SolarThing is communicating fine with your serial adapter, but it cannot reach the device.\n" + "Make sure the cable you have has the correct pinout, and feel free to open an issue at https://github.com/wildmountainfarms/solarthing/issues if you need help.\n");
}
} else if (e instanceof ParsedResponseException) {
ParsedResponseException parsedResponseException = (ParsedResponseException) e;
ModbusMessage message = parsedResponseException.getResponse();
String hexFunctionCode = String.format("%02X", message.getFunctionCode());
LOGGER.info("Communication with rover working well. Got this response back: function code=0x" + hexFunctionCode + " data='" + dataToSplitHex(message.getByteData()) + "' feel free to open issue at https://github.com/wildmountainfarms/solarthing/issues/");
} else if (e instanceof RawResponseException) {
byte[] data = ((RawResponseException) e).getRawData();
LOGGER.info("Got part of a response back. (Maybe timed out halfway through?) data='" + dataToSplitHex(data) + "' Feel free to open an issue at https://github.com/wildmountainfarms/solarthing/issues/");
}
if (isTimeout) {
successReporter.reportTimeout();
} else {
successReporter.reportSuccessWithError();
}
return;
}
hasBeenSuccessful = true;
successReporter.reportSuccess();
final long readDurationNanos = System.nanoTime() - startTimeNanos;
LOGGER.debug("took " + TimeUtil.nanosToSecondsString(readDurationNanos) + " seconds to read from device");
}
use of me.retrodaredevil.io.modbus.ModbusRuntimeException in project solarthing by wildmountainfarms.
the class TracerPacketListUpdater method receive.
@Override
public void receive(List<Packet> packets) {
TracerStatusPacket packet = TracerStatusPackets.createFromReadTable(number, read);
packets.add(packet);
if (tracerClockOptions != null) {
// Sorry to anyone in the year 2256, that's just too bad for you
// We make the year 21 represent 2021, because the tracer stores the year using 8 bits
LocalDateTime currentTime = packet.getSolarThingLocalDateTime();
final LocalDateTime desiredTime;
ZoneOffset zoneOffset = tracerClockOptions.getZoneOffset();
if (zoneOffset != null) {
desiredTime = Instant.now().atOffset(zoneOffset).toLocalDateTime();
} else {
ZoneId zone = tracerClockOptions.getZoneId() != null ? tracerClockOptions.getZoneId() : ZoneId.systemDefault();
desiredTime = Instant.now().atZone(zone).toLocalDateTime();
}
if (Duration.between(currentTime, desiredTime).abs().compareTo(tracerClockOptions.getDurationThreshold()) > 0) {
LOGGER.info("Going to update time to " + desiredTime + " from " + currentTime);
write.setSolarThingLocalDateTime(desiredTime);
LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "Success updating time!");
}
}
if (connectionHandler != null) {
TracerBatteryConfigBuilder builder = new TracerBatteryConfigBuilder(packet);
connectionHandler.handleRequests(request -> {
String[] split = StringUtil.terminalSplit(request);
if (split.length == 1) {
if ("flushBatteryConfig".equals(split[0])) {
try {
write.setBatteryConfig(builder);
} catch (FunctionCodeException ex) {
return ex.getMessage();
} catch (ModbusRuntimeException ex) {
LOGGER.error("Got modbus exception while flushing", ex);
return "Unknown error:" + ex.getMessage();
}
return "flush success";
}
}
if (connectionHandlerHasFlushLogic && split.length > 1) {
// check if we're writing something
String fieldName = split[0];
String value = split[1];
// If we can successfully read from this reader, then that means that the input is a field in TracerBatteryConfigBuilder
//
ObjectReader reader = MAPPER.readerForUpdating(builder);
ObjectNode input = new ObjectNode(JsonNodeFactory.instance);
input.put(fieldName, value);
boolean success = true;
try {
reader.readValue(input);
} catch (IOException e) {
success = false;
}
if (success) {
return "queued up";
}
}
return NetCatUtil.handle(write, packet, request);
});
}
}
Aggregations