Skip to content

Commit

Permalink
Filter messages from command response (#2627)
Browse files Browse the repository at this point in the history
  • Loading branch information
breiler authored Oct 25, 2024
1 parent 3101add commit 8910a84
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public void appendResponse(String response) {
return;
}

// Do not append messages
if (response.startsWith("[MSG:")) {
return;
}

super.appendResponse(response);

if (response.startsWith("ok")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.willwinder.universalgcodesender.firmware.fluidnc.commands;

import com.willwinder.universalgcodesender.types.CommandException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

import java.util.Map;

import static org.junit.Assert.*;

public class GetFirmwareSettingsCommandTest {
@Test
public void appendResponseWithYamlConfigShouldParseSettingsAsYaml() {
Expand All @@ -29,6 +28,27 @@ public void appendResponseWithYamlConfigShouldParseSettingsAsYaml() {
assertEquals("800", settings.get("axis/y/steps_per_mm"));
}

@Test
public void appendResponseShouldIgnoreMessages() {
GetFirmwareSettingsCommand command = new GetFirmwareSettingsCommand();
command.appendResponse("axis:");
command.appendResponse(" shared_stepper_disable_pin: gpio.13:low");
command.appendResponse(" shared_stepper_reset_pin: NO_PIN");
command.appendResponse(" x:");
command.appendResponse("[MSG:INFO: Huanyang PD014 Accel:6.000]");
command.appendResponse(" steps_per_mm: 800");
command.appendResponse(" y:");
command.appendResponse(" steps_per_mm: 800");
command.appendResponse("ok");

Map<String, String> settings = command.getSettings();
assertEquals(4, settings.keySet().size());
assertEquals("gpio.13:low", settings.get("axis/shared_stepper_disable_pin"));
assertEquals("NO_PIN", settings.get("axis/shared_stepper_reset_pin"));
assertEquals("800", settings.get("axis/x/steps_per_mm"));
assertEquals("800", settings.get("axis/y/steps_per_mm"));
}

@Test
public void getSettingsShouldThrowExceptionOnFaultyYaml() {
GetFirmwareSettingsCommand command = new GetFirmwareSettingsCommand();
Expand Down

0 comments on commit 8910a84

Please sign in to comment.