diff --git a/ugs-core/src/com/willwinder/universalgcodesender/AbstractController.java b/ugs-core/src/com/willwinder/universalgcodesender/AbstractController.java index 6f5cfaaa6a..c11b72ee64 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/AbstractController.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/AbstractController.java @@ -18,16 +18,32 @@ This file is part of Universal Gcode Sender (UGS). */ package com.willwinder.universalgcodesender; -import com.willwinder.universalgcodesender.communicator.ICommunicatorListener; +import static com.willwinder.universalgcodesender.Utils.formatter; import com.willwinder.universalgcodesender.communicator.ICommunicator; +import com.willwinder.universalgcodesender.communicator.ICommunicatorListener; import com.willwinder.universalgcodesender.connection.ConnectionDriver; import com.willwinder.universalgcodesender.gcode.GcodeParser; import com.willwinder.universalgcodesender.gcode.GcodeState; import com.willwinder.universalgcodesender.gcode.ICommandCreator; import com.willwinder.universalgcodesender.gcode.util.GcodeUtils; import com.willwinder.universalgcodesender.i18n.Localization; -import com.willwinder.universalgcodesender.listeners.*; -import com.willwinder.universalgcodesender.model.*; +import com.willwinder.universalgcodesender.listeners.ControllerListener; +import com.willwinder.universalgcodesender.listeners.ControllerState; +import com.willwinder.universalgcodesender.listeners.ControllerStatus; +import com.willwinder.universalgcodesender.listeners.MessageType; +import com.willwinder.universalgcodesender.model.Alarm; +import com.willwinder.universalgcodesender.model.Axis; +import com.willwinder.universalgcodesender.model.CommunicatorState; +import static com.willwinder.universalgcodesender.model.CommunicatorState.COMM_CHECK; +import static com.willwinder.universalgcodesender.model.CommunicatorState.COMM_DISCONNECTED; +import static com.willwinder.universalgcodesender.model.CommunicatorState.COMM_IDLE; +import static com.willwinder.universalgcodesender.model.CommunicatorState.COMM_SENDING; +import static com.willwinder.universalgcodesender.model.CommunicatorState.COMM_SENDING_PAUSED; +import com.willwinder.universalgcodesender.model.PartialPosition; +import com.willwinder.universalgcodesender.model.Position; +import com.willwinder.universalgcodesender.model.UnitUtils; +import static com.willwinder.universalgcodesender.model.UnitUtils.Units.MM; +import static com.willwinder.universalgcodesender.model.UnitUtils.scaleUnits; import com.willwinder.universalgcodesender.services.MessageService; import com.willwinder.universalgcodesender.types.GcodeCommand; import com.willwinder.universalgcodesender.utils.IGcodeStreamReader; @@ -46,11 +62,6 @@ This file is part of Universal Gcode Sender (UGS). import java.util.logging.Level; import java.util.logging.Logger; -import static com.willwinder.universalgcodesender.Utils.formatter; -import static com.willwinder.universalgcodesender.model.CommunicatorState.*; -import static com.willwinder.universalgcodesender.model.UnitUtils.Units.MM; -import static com.willwinder.universalgcodesender.model.UnitUtils.scaleUnits; - /** * Abstract Control layer, coordinates all aspects of control. * @@ -344,9 +355,9 @@ public Boolean openCommPort(ConnectionDriver connectionDriver, String port, int } // No point in checking response, it throws an exception on errors. - this.comm.connect(connectionDriver, port, portRate); this.setCurrentState(COMM_IDLE); this.setControllerState(ControllerState.CONNECTING); + this.comm.connect(connectionDriver, port, portRate); if (isCommOpen()) { dispatchConsoleMessage(MessageType.INFO, diff --git a/ugs-core/src/com/willwinder/universalgcodesender/firmware/fluidnc/FluidNCController.java b/ugs-core/src/com/willwinder/universalgcodesender/firmware/fluidnc/FluidNCController.java index 2409b79c05..3d639e50f0 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/firmware/fluidnc/FluidNCController.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/firmware/fluidnc/FluidNCController.java @@ -332,9 +332,9 @@ public Boolean openCommPort(ConnectionDriver connectionDriver, String port, int isInitialized = false; positionPollTimer.stop(); - communicator.connect(connectionDriver, port, portRate); setControllerState(ControllerState.CONNECTING); messageService.dispatchMessage(MessageType.INFO, "*** Connecting to " + connectionDriver.getProtocol() + port + ":" + portRate + "\n"); + communicator.connect(connectionDriver, port, portRate); ThreadHelper.invokeLater(() -> { if (StringUtils.isEmpty(firmwareVariant) || semanticVersion == null) { diff --git a/ugs-core/src/com/willwinder/universalgcodesender/gcode/util/Code.java b/ugs-core/src/com/willwinder/universalgcodesender/gcode/util/Code.java index d7c2057173..5d16c32740 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/gcode/util/Code.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/gcode/util/Code.java @@ -1,5 +1,5 @@ /* - Copyright 2017 Will Winder + Copyright 2017-2024 Will Winder This file is part of Universal Gcode Sender (UGS). @@ -53,10 +53,10 @@ public enum Code { G2(Motion, false, true), G3(Motion, false, true), G33(Motion), - G38_2(Motion), - G38_3(Motion), - G38_4(Motion), - G38_5(Motion), + G38_2(Motion, false, true), + G38_3(Motion, false, true), + G38_4(Motion, false, true), + G38_5(Motion, false, true), G73(Motion), G76(Motion), G80(Motion, false, true), diff --git a/ugs-core/src/com/willwinder/universalgcodesender/gcode/util/GcodeParserUtils.java b/ugs-core/src/com/willwinder/universalgcodesender/gcode/util/GcodeParserUtils.java index a740c75cd3..4fe86b882d 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/gcode/util/GcodeParserUtils.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/gcode/util/GcodeParserUtils.java @@ -1,5 +1,5 @@ /* - Copyright 2017-2023 Will Winder + Copyright 2017-2024 Will Winder This file is part of Universal Gcode Sender (UGS). @@ -23,6 +23,14 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.universalgcodesender.gcode.GcodeParser; import com.willwinder.universalgcodesender.gcode.GcodePreprocessorUtils; import com.willwinder.universalgcodesender.gcode.GcodeState; +import static com.willwinder.universalgcodesender.gcode.util.Code.G20; +import static com.willwinder.universalgcodesender.gcode.util.Code.G21; +import static com.willwinder.universalgcodesender.gcode.util.Code.G90; +import static com.willwinder.universalgcodesender.gcode.util.Code.G90_1; +import static com.willwinder.universalgcodesender.gcode.util.Code.G91; +import static com.willwinder.universalgcodesender.gcode.util.Code.G91_1; +import static com.willwinder.universalgcodesender.gcode.util.Code.ModalGroup.Motion; +import static com.willwinder.universalgcodesender.gcode.util.Code.UNKNOWN; import com.willwinder.universalgcodesender.i18n.Localization; import com.willwinder.universalgcodesender.model.Position; import com.willwinder.universalgcodesender.model.UnitUtils; @@ -49,17 +57,7 @@ This file is part of Universal Gcode Sender (UGS). import java.util.logging.Logger; import java.util.stream.Collectors; -import static com.willwinder.universalgcodesender.gcode.util.Code.G20; -import static com.willwinder.universalgcodesender.gcode.util.Code.G21; -import static com.willwinder.universalgcodesender.gcode.util.Code.G90; -import static com.willwinder.universalgcodesender.gcode.util.Code.G90_1; -import static com.willwinder.universalgcodesender.gcode.util.Code.G91; -import static com.willwinder.universalgcodesender.gcode.util.Code.G91_1; -import static com.willwinder.universalgcodesender.gcode.util.Code.ModalGroup.Motion; -import static com.willwinder.universalgcodesender.gcode.util.Code.UNKNOWN; - /** - * * @author wwinder */ public class GcodeParserUtils { @@ -174,6 +172,10 @@ public static List processCommand(String command, int lin } private static PointSegment addProbePointSegment(Position nextPoint, boolean fastTraverse, int line, GcodeState state) { + if (nextPoint == null) { + return null; + } + PointSegment ps = addLinearPointSegment(nextPoint, fastTraverse, line, state); ps.setIsProbe(true); return ps; @@ -391,7 +393,7 @@ private static void preprocessAndWrite(GcodeParser gcp, IGcodeWriter gsw, String // Parse the gcode for the buffer. Collection lines = gcp.preprocessCommand(command, gcp.getCurrentState()); - for(String processedLine : lines) { + for (String processedLine : lines) { gsw.addLine(command, processedLine, comment, idx); } @@ -400,6 +402,7 @@ private static void preprocessAndWrite(GcodeParser gcp, IGcodeWriter gsw, String /** * Attempts to read the input file in GcodeStream format. + * * @return whether or not we succeed processing the file. */ private static boolean processAndExportGcodeStream(GcodeParser gcp, InputStream input, IGcodeWriter output) @@ -424,14 +427,15 @@ private static boolean processAndExportGcodeStream(GcodeParser gcp, InputStream /** * Attempts to read the input file in gcode-text format. + * * @return whether or not we succeed processing the file. */ private static void processAndExportText(GcodeParser gcp, BufferedReader input, IGcodeWriter output) throws IOException, GcodeParserException { // Preprocess a regular gcode file. - try(BufferedReader br = input) { + try (BufferedReader br = input) { int i = 0; - for(String line; (line = br.readLine()) != null; ) { + for (String line; (line = br.readLine()) != null; ) { i++; String comment = GcodePreprocessorUtils.parseComment(line); diff --git a/ugs-core/test/com/willwinder/universalgcodesender/gcode/util/GcodeParserUtilsTest.java b/ugs-core/test/com/willwinder/universalgcodesender/gcode/util/GcodeParserUtilsTest.java index d920cd3a99..9eb195a30d 100644 --- a/ugs-core/test/com/willwinder/universalgcodesender/gcode/util/GcodeParserUtilsTest.java +++ b/ugs-core/test/com/willwinder/universalgcodesender/gcode/util/GcodeParserUtilsTest.java @@ -3,19 +3,19 @@ import com.google.common.collect.Iterables; import com.willwinder.universalgcodesender.gcode.GcodeParser; import com.willwinder.universalgcodesender.gcode.GcodeState; -import com.willwinder.universalgcodesender.i18n.Localization; -import com.willwinder.universalgcodesender.model.Position; -import org.junit.Assert; -import org.junit.Test; - -import java.util.List; - import static com.willwinder.universalgcodesender.gcode.util.Code.G0; import static com.willwinder.universalgcodesender.gcode.util.Code.G1; import static com.willwinder.universalgcodesender.gcode.util.Code.G3; +import static com.willwinder.universalgcodesender.gcode.util.Code.G38_2; +import com.willwinder.universalgcodesender.i18n.Localization; +import com.willwinder.universalgcodesender.model.Position; import static com.willwinder.universalgcodesender.model.UnitUtils.Units.MM; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import org.junit.Assert; +import org.junit.Test; + +import java.util.List; public class GcodeParserUtilsTest { @Test @@ -36,10 +36,11 @@ public void multipleAxisWordCommands() { } @Test - public void missingAxisWords() { - assertThatThrownBy(() -> GcodeParserUtils.processCommand("G38.2", 0, new GcodeState())) - .isInstanceOf(GcodeParserException.class) - .hasMessage(Localization.getString("parser.gcode.missing-axis-commands") + ": G38.2"); + public void missingAxisWords() throws GcodeParserException { + List metaList = GcodeParserUtils.processCommand("G38.2", 0, new GcodeState()); + GcodeParser.GcodeMeta meta = Iterables.getOnlyElement(metaList); + assertThat(meta.code).isEqualTo(G38_2); + assertThat(meta.state.currentPoint).isEqualTo(new Position(0, 0, 0, MM)); } @Test