Skip to content

Commit

Permalink
Fix problem with fluidnc version without a leading v in version number (
Browse files Browse the repository at this point in the history
  • Loading branch information
breiler authored Nov 9, 2023
1 parent ff90545 commit 39ec06d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.]+ (?<variant>[a-zA-Z0-9]+) v(?<version>(?<major>[0-9]*)(.(?<minor>[0-9]+)(.(?<patch>[0-9]+))?)?([a-zA-Z]+)?)(.*:.*)*]", Pattern.CASE_INSENSITIVE);
private static final Pattern VERSION_FLUIDNC_PATTERN = Pattern.compile("\\[VER:[0-9.]+ (?<variant>[a-zA-Z0-9]+) v?(?<version>(?<major>[0-9]*)(.(?<minor>[0-9]+)(.(?<patch>[0-9]+))?)?([a-zA-Z]+)?)(.*:.*)*]", Pattern.CASE_INSENSITIVE);
private static final Pattern VERSION_GRBL_PATTERN = Pattern.compile("\\[VER:(?<version>(?<major>[0-9]*)(.(?<minor>[0-9]+)(.(?<patch>[0-9]+))?)).*]", Pattern.CASE_INSENSITIVE);

public GetFirmwareVersionCommand() {
Expand All @@ -36,7 +36,7 @@ public GetFirmwareVersionCommand() {

public String getFirmware() {
Optional<String> firmwareOptional = parseFluidNCVariant();
if (!firmwareOptional.isPresent()) {
if (firmwareOptional.isEmpty()) {
firmwareOptional = parseGrblVariant();
}

Expand Down Expand Up @@ -67,7 +67,7 @@ private Optional<String> parseFluidNCVariant() {

public SemanticVersion getVersion() {
Optional<SemanticVersion> versionOptional = parseFluidNCVs();
if (!versionOptional.isPresent()) {
if (versionOptional.isEmpty()) {
versionOptional = parseGrblVersion();
}
return versionOptional.orElse(new SemanticVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 39ec06d

Please sign in to comment.