Search in sources :

Example 1 with ControllerStatus

use of com.willwinder.universalgcodesender.listeners.ControllerStatus in project Universal-G-Code-Sender by winder.

the class TinyGController method rawResponseHandler.

@Override
protected void rawResponseHandler(String response) {
    JsonObject jo;
    try {
        jo = TinyGUtils.jsonToObject(response);
    } catch (Exception e) {
        // this.messageForConsole(response + "\n");
        return;
    }
    if (TinyGUtils.isRestartingResponse(jo)) {
        this.messageForConsole("[restarting] " + response + "\n");
        this.isReady = false;
    } else if (TinyGUtils.isReadyResponse(jo)) {
        // this.messageForConsole("Got version: " + TinyGUtils.getVersion(jo) + "\n");
        this.messageForConsole("[ready] " + response + "\n");
        this.isReady = true;
    } else if (TinyGUtils.isStatusResponse(jo)) {
        TinyGUtils.StatusResult result = TinyGUtils.updateStatus(jo);
        state = result.state;
        machineLocation.set(result.machine);
        workLocation.set(result.work);
        ControllerStatus cs = new ControllerStatus(state, machineLocation, workLocation);
        dispatchStatusString(cs);
    } else if (TinyGGcodeCommand.isOkErrorResponse(response)) {
        try {
            this.commandComplete(response);
        } catch (Exception e) {
            this.errorMessageForConsole(Localization.getString("controller.error.response") + " <" + response + ">: " + e.getMessage());
        }
        this.messageForConsole(response + "\n");
    } else {
        // Display any unhandled messages
        this.messageForConsole("[unhandled message] " + response + "\n");
    }
}
Also used : ControllerStatus(com.willwinder.universalgcodesender.listeners.ControllerStatus) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException)

Example 2 with ControllerStatus

use of com.willwinder.universalgcodesender.listeners.ControllerStatus in project Universal-G-Code-Sender by winder.

the class GrblUtilsTest method getStatusFromStringVersion1WhereFeedOverridesFeedSpindleStatusString.

@Test
public void getStatusFromStringVersion1WhereFeedOverridesFeedSpindleStatusString() {
    String status = "<Idle|WPos:4.0,5.0,6.0|WCO:7.0,8.0,9.0|Ov:1,2,3|FS:12345.7,65432.1|F:12345.6|Pn:XYZPDHRS|A:SFMC>";
    Capabilities version = new Capabilities();
    version.addCapability(GrblCapabilitiesConstants.V1_FORMAT);
    UnitUtils.Units unit = UnitUtils.Units.MM;
    ControllerStatus controllerStatus = GrblUtils.getStatusFromStatusString(null, status, version, unit);
    assertEquals(Double.valueOf(12345.6), controllerStatus.getFeedSpeed());
    assertEquals(Double.valueOf(65432.1), controllerStatus.getSpindleSpeed());
}
Also used : UnitUtils(com.willwinder.universalgcodesender.model.UnitUtils) ControllerStatus(com.willwinder.universalgcodesender.listeners.ControllerStatus) Test(org.junit.Test)

Example 3 with ControllerStatus

use of com.willwinder.universalgcodesender.listeners.ControllerStatus in project Universal-G-Code-Sender by winder.

the class GrblUtilsTest method getStatusFromStringVersion1WithoutPinsStatusString.

@Test
public void getStatusFromStringVersion1WithoutPinsStatusString() {
    String status = "<Idle|WPos:4.0,5.0,6.0|WCO:7.0,8.0,9.0|Ov:1,2,3|FS:12345.7,65432.1|F:12345.6|A:SFMC>";
    Capabilities version = new Capabilities();
    version.addCapability(GrblCapabilitiesConstants.V1_FORMAT);
    UnitUtils.Units unit = UnitUtils.Units.MM;
    ControllerStatus controllerStatus = GrblUtils.getStatusFromStatusString(null, status, version, unit);
    assertFalse(controllerStatus.getEnabledPins().CycleStart);
    assertFalse(controllerStatus.getEnabledPins().Door);
    assertFalse(controllerStatus.getEnabledPins().Hold);
    assertFalse(controllerStatus.getEnabledPins().SoftReset);
    assertFalse(controllerStatus.getEnabledPins().Probe);
    assertFalse(controllerStatus.getEnabledPins().X);
    assertFalse(controllerStatus.getEnabledPins().Y);
    assertFalse(controllerStatus.getEnabledPins().Z);
}
Also used : UnitUtils(com.willwinder.universalgcodesender.model.UnitUtils) ControllerStatus(com.willwinder.universalgcodesender.listeners.ControllerStatus) Test(org.junit.Test)

Example 4 with ControllerStatus

use of com.willwinder.universalgcodesender.listeners.ControllerStatus in project Universal-G-Code-Sender by winder.

the class GrblUtilsTest method getStatusFromStringVersion1WithoutWorkCoordinateOffsetStatusString.

@Test
public void getStatusFromStringVersion1WithoutWorkCoordinateOffsetStatusString() {
    String status = "<Idle|MPos:1.1,2.2,3.3|WPos:4.4,5.5,6.6|Ov:1,2,3|F:12345.6|FS:12345.7,65432.1|Pn:XYZPDHRS|A:SFMC>";
    Capabilities version = new Capabilities();
    version.addCapability(GrblCapabilitiesConstants.V1_FORMAT);
    UnitUtils.Units unit = UnitUtils.Units.MM;
    ControllerStatus controllerStatus = GrblUtils.getStatusFromStatusString(null, status, version, unit);
    assertEquals(new Position(1.1, 2.2, 3.3, UnitUtils.Units.MM), controllerStatus.getMachineCoord());
    assertEquals(new Position(4.4, 5.5, 6.6, UnitUtils.Units.MM), controllerStatus.getWorkCoord());
    assertEquals(new Position(0, 0, 0, UnitUtils.Units.MM), controllerStatus.getWorkCoordinateOffset());
}
Also used : UnitUtils(com.willwinder.universalgcodesender.model.UnitUtils) ControllerStatus(com.willwinder.universalgcodesender.listeners.ControllerStatus) Position(com.willwinder.universalgcodesender.model.Position) Test(org.junit.Test)

Example 5 with ControllerStatus

use of com.willwinder.universalgcodesender.listeners.ControllerStatus in project Universal-G-Code-Sender by winder.

the class GrblUtilsTest method getStatusFromStringVersion1WithoutWorkCoordinateStatusString.

@Test
public void getStatusFromStringVersion1WithoutWorkCoordinateStatusString() {
    String status = "<Idle|MPos:1.0,2.0,3.0|WCO:7.0,8.0,9.0|Ov:1,2,3|F:12345.6|FS:12345.7,65432.1|Pn:XYZPDHRS|A:SFMC>";
    Capabilities version = new Capabilities();
    version.addCapability(GrblCapabilitiesConstants.V1_FORMAT);
    UnitUtils.Units unit = UnitUtils.Units.MM;
    ControllerStatus controllerStatus = GrblUtils.getStatusFromStatusString(null, status, version, unit);
    assertEquals(new Position(1, 2, 3, UnitUtils.Units.MM), controllerStatus.getMachineCoord());
    assertEquals(new Position(-6, -6, -6, UnitUtils.Units.MM), controllerStatus.getWorkCoord());
    assertEquals(new Position(7, 8, 9, UnitUtils.Units.MM), controllerStatus.getWorkCoordinateOffset());
}
Also used : UnitUtils(com.willwinder.universalgcodesender.model.UnitUtils) ControllerStatus(com.willwinder.universalgcodesender.listeners.ControllerStatus) Position(com.willwinder.universalgcodesender.model.Position) Test(org.junit.Test)

Aggregations

ControllerStatus (com.willwinder.universalgcodesender.listeners.ControllerStatus)10 UnitUtils (com.willwinder.universalgcodesender.model.UnitUtils)7 Test (org.junit.Test)7 Position (com.willwinder.universalgcodesender.model.Position)6 JsonObject (com.google.gson.JsonObject)1 AccessoryStates (com.willwinder.universalgcodesender.listeners.ControllerStatus.AccessoryStates)1 EnabledPins (com.willwinder.universalgcodesender.listeners.ControllerStatus.EnabledPins)1 OverridePercents (com.willwinder.universalgcodesender.listeners.ControllerStatus.OverridePercents)1 GcodeCommand (com.willwinder.universalgcodesender.types.GcodeCommand)1 GrblFeedbackMessage (com.willwinder.universalgcodesender.types.GrblFeedbackMessage)1 GrblSettingMessage (com.willwinder.universalgcodesender.types.GrblSettingMessage)1 IOException (java.io.IOException)1