diff --git a/ugs-core/src/com/willwinder/universalgcodesender/firmware/fluidnc/commands/GetFirmwareVersionCommand.java b/ugs-core/src/com/willwinder/universalgcodesender/firmware/fluidnc/commands/GetFirmwareVersionCommand.java index e6f8530319..0f2114c60d 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/firmware/fluidnc/commands/GetFirmwareVersionCommand.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/firmware/fluidnc/commands/GetFirmwareVersionCommand.java @@ -27,7 +27,7 @@ This file is part of Universal Gcode Sender (UGS). import java.util.regex.Pattern; public class GetFirmwareVersionCommand extends SystemCommand { - private static final Pattern VERSION_FLUIDNC_PATTERN = Pattern.compile("\\[VER:[0-9.]+ (?[a-zA-Z0-9]+) v(?(?[0-9]*)(.(?[0-9]+)(.(?[0-9]+))?)?([a-zA-Z]+)?)(.*:.*)*]", Pattern.CASE_INSENSITIVE); + private static final Pattern VERSION_FLUIDNC_PATTERN = Pattern.compile("\\[VER:[0-9.]+ (?[a-zA-Z0-9]+) v?(?(?[0-9]*)(.(?[0-9]+)(.(?[0-9]+))?)?([a-zA-Z]+)?)(.*:.*)*]", Pattern.CASE_INSENSITIVE); private static final Pattern VERSION_GRBL_PATTERN = Pattern.compile("\\[VER:(?(?[0-9]*)(.(?[0-9]+)(.(?[0-9]+))?)).*]", Pattern.CASE_INSENSITIVE); public GetFirmwareVersionCommand() { @@ -36,7 +36,7 @@ public GetFirmwareVersionCommand() { public String getFirmware() { Optional firmwareOptional = parseFluidNCVariant(); - if (!firmwareOptional.isPresent()) { + if (firmwareOptional.isEmpty()) { firmwareOptional = parseGrblVariant(); } @@ -67,7 +67,7 @@ private Optional parseFluidNCVariant() { public SemanticVersion getVersion() { Optional versionOptional = parseFluidNCVs(); - if (!versionOptional.isPresent()) { + if (versionOptional.isEmpty()) { versionOptional = parseGrblVersion(); } return versionOptional.orElse(new SemanticVersion()); diff --git a/ugs-core/test/com/willwinder/universalgcodesender/firmware/fluidnc/commands/GetFirmwareVersionCommandTest.java b/ugs-core/test/com/willwinder/universalgcodesender/firmware/fluidnc/commands/GetFirmwareVersionCommandTest.java index b28e66f71e..19f95e64e2 100644 --- a/ugs-core/test/com/willwinder/universalgcodesender/firmware/fluidnc/commands/GetFirmwareVersionCommandTest.java +++ b/ugs-core/test/com/willwinder/universalgcodesender/firmware/fluidnc/commands/GetFirmwareVersionCommandTest.java @@ -29,6 +29,18 @@ public void getFirmwareVersionWithVersion() { assertEquals("FluidNC", getFirmwareVersionCommand.getFirmware()); } + @Test + public void getFirmwareVersionWithoutLeadingV() { + GetFirmwareVersionCommand getFirmwareVersionCommand = new GetFirmwareVersionCommand(); + getFirmwareVersionCommand.appendResponse("[VER:3.7 FluidNC 3.7.10:]"); + + assertNotNull(getFirmwareVersionCommand.getVersion()); + assertEquals(3, getFirmwareVersionCommand.getVersion().getMajor()); + assertEquals(7, getFirmwareVersionCommand.getVersion().getMinor()); + assertEquals(10, getFirmwareVersionCommand.getVersion().getPatch()); + assertEquals("FluidNC", getFirmwareVersionCommand.getFirmware()); + } + @Test public void getFirmwareVersionWithOldGRBLVersion() { GetFirmwareVersionCommand getFirmwareVersionCommand = new GetFirmwareVersionCommand();