Skip to content

Commit

Permalink
Handle locked alarm state on connect in FluidNC
Browse files Browse the repository at this point in the history
  • Loading branch information
breiler committed Nov 26, 2024
1 parent a201720 commit 0d31d15
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,13 @@ public static boolean isControllerResponsive(IController controller, MessageServ
throw new IllegalStateException("Could not query the device status");
}

// The controller is in a locked DOOR state and needs to be reset
if (statusCommand.getControllerStatus().getState() == ControllerState.DOOR) {
return false;
}

// The controller is not up and running properly
if (statusCommand.getControllerStatus().getState() == ControllerState.HOLD || statusCommand.getControllerStatus().getState() == ControllerState.ALARM) {
if (statusCommand.getControllerStatus().getState() == ControllerState.HOLD || statusCommand.getControllerStatus().getState() == ControllerState.DOOR || statusCommand.getControllerStatus().getState() == ControllerState.ALARM) {
try {
// Figure out if it is still responsive even if it is in HOLD or ALARM state
sendAndWaitForCompletion(controller, new SystemCommand(""));
// We can do this
SystemCommand systemCommand = sendAndWaitForCompletion(controller, new SystemCommand("$I"));
return systemCommand.isOk();
} catch (Exception e) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,11 @@ public void isControllerResponsiveWhenControllerInStateHold() throws Exception {
return null;
}).when(controller).sendCommandImmediately(any(GetStatusCommand.class));

// Responds with ok on empty system command
doAnswer(answer -> {
GcodeCommand command = answer.getArgument(0, GcodeCommand.class);
command.appendResponse("ok");
return null;
}).when(controller).sendCommandImmediately(ArgumentMatchers.argThat(command -> command.getCommandString().equals("")));
}).when(controller).sendCommandImmediately(ArgumentMatchers.argThat(command -> command.getCommandString().equals("$I")));

assertTrue(FluidNCUtils.isControllerResponsive(controller, messageService));
}
Expand All @@ -172,6 +171,13 @@ public void isControllerResponsiveWhenControllerInStateDoor() throws Exception {
command.appendResponse("<Door:0>");
return null;
}).when(controller).sendCommandImmediately(any(GetStatusCommand.class));

doAnswer(answer -> {
GcodeCommand command = answer.getArgument(0, GcodeCommand.class);
command.appendResponse("error:8");
return null;
}).when(controller).sendCommandImmediately(ArgumentMatchers.argThat(command -> command.getCommandString().equals("$I")));

assertFalse(FluidNCUtils.isControllerResponsive(controller, messageService));
}

Expand All @@ -188,16 +194,37 @@ public void isControllerResponsiveWhenControllerInAlarm() throws Exception {
return null;
}).when(controller).sendCommandImmediately(any(GetStatusCommand.class));

// Responds with ok on empty system command
doAnswer(answer -> {
GcodeCommand command = answer.getArgument(0, GcodeCommand.class);
command.appendResponse("ok");
return null;
}).when(controller).sendCommandImmediately(ArgumentMatchers.argThat(command -> command.getCommandString().equals("")));
}).when(controller).sendCommandImmediately(ArgumentMatchers.argThat(command -> command.getCommandString().equals("$I")));

assertTrue(FluidNCUtils.isControllerResponsive(controller, messageService));
}

@Test
public void isControllerResponsiveWhenControllerInLockedAlarm() throws Exception {
IController controller = mock(IController.class);
when(controller.isCommOpen()).thenReturn(true);
MessageService messageService = mock(MessageService.class);

// Respond with status hold
doAnswer(answer -> {
GcodeCommand command = answer.getArgument(0, GcodeCommand.class);
command.appendResponse("<Alarm>");
return null;
}).when(controller).sendCommandImmediately(any(GetStatusCommand.class));

doAnswer(answer -> {
GcodeCommand command = answer.getArgument(0, GcodeCommand.class);
command.appendResponse("error:8");
return null;
}).when(controller).sendCommandImmediately(ArgumentMatchers.argThat(command -> command.getCommandString().equals("$I")));

assertFalse(FluidNCUtils.isControllerResponsive(controller, messageService));
}

@Test
public void isControllerResponsiveWhenControllerInAlarmAndNotResponsive() throws Exception {
IController controller = mock(IController.class);
Expand Down

0 comments on commit 0d31d15

Please sign in to comment.