Search in sources :

Example 41 with GcodeCommand

use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.

the class AbstractControllerTest method testGetSendDuration.

/**
 * Test of getSendDuration method, of class AbstractController.
 */
@Test
public void testGetSendDuration() throws Exception {
    System.out.println("getSendDuration");
    String command = "command";
    String port = "/some/port";
    int rate = 1234;
    startStreamExpectation(port, rate, command, false);
    expect(mockCommunicator.numActiveCommands()).andReturn(1);
    expect(mockCommunicator.numActiveCommands()).andReturn(0);
    EasyMock.replay(instance, mockCommunicator);
    // Time starts at zero when nothing has been sent.
    assertEquals(0L, instance.getSendDuration());
    startStream(port, rate, command);
    long start = System.currentTimeMillis();
    Thread.sleep(1000);
    long time = instance.getSendDuration();
    long checkpoint = System.currentTimeMillis();
    // Began streaming at least 1 second ago.
    assertTrue(time > (start - checkpoint));
    Thread.sleep(1000);
    instance.commandSent(new GcodeCommand(command));
    instance.commandSent(new GcodeCommand(command));
    instance.commandComplete(command);
    instance.commandComplete(command);
    time = instance.getSendDuration();
    checkpoint = System.currentTimeMillis();
    // Completed commands after at least "checkpoint" milliseconds.
    assertTrue(time > (start - checkpoint));
    Thread.sleep(1000);
    // Make sure the time stopped after the last command was completed.
    long newtime = instance.getSendDuration();
    assertEquals(time, newtime);
    EasyMock.verify(mockCommunicator, instance);
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) EasyMock.anyString(org.easymock.EasyMock.anyString) Test(org.junit.Test) GcodeStreamTest(com.willwinder.universalgcodesender.utils.GcodeStreamTest)

Example 42 with GcodeCommand

use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.

the class BufferedCommunicatorTest method responseMessageOnErrorShouldPauseTheCommunicator.

@Test
public void responseMessageOnErrorShouldPauseTheCommunicator() {
    // Given
    Connection connection = mock(Connection.class);
    instance.setConnection(connection);
    asl.add(new GcodeCommand("G0"));
    asl.add(new GcodeCommand("G0"));
    instance.streamCommands();
    // When
    instance.responseMessage("error");
    // Then
    assertTrue(instance.isPaused());
}
Also used : Connection(com.willwinder.universalgcodesender.connection.Connection) GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) Test(org.junit.Test) GcodeStreamTest(com.willwinder.universalgcodesender.utils.GcodeStreamTest)

Example 43 with GcodeCommand

use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.

the class BufferedCommunicatorTest method testResponseMessage.

/**
 * Test of responseMessage method, of class BufferedCommunicator.
 */
@Test
public void testResponseMessage() throws Exception {
    System.out.println("responseMessage");
    String first = "not-handled";
    mockScl.rawResponseListener(first);
    EasyMock.expect(EasyMock.expectLastCall()).once();
    mockScl.rawResponseListener("ok");
    EasyMock.expect(EasyMock.expectLastCall()).once();
    EasyMock.replay(mockScl);
    asl.add(new GcodeCommand("command"));
    instance.responseMessage(first);
    assertEquals(1, asl.size());
    instance.responseMessage("ok");
    assertEquals(0, asl.size());
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) Test(org.junit.Test) GcodeStreamTest(com.willwinder.universalgcodesender.utils.GcodeStreamTest)

Example 44 with GcodeCommand

use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.

the class BufferedCommunicatorTest method responseMessageOnErrorOnLastCommandShouldNotPauseTheCommunicator.

@Test
public void responseMessageOnErrorOnLastCommandShouldNotPauseTheCommunicator() {
    // Given
    Connection connection = mock(Connection.class);
    instance.setConnection(connection);
    asl.add(new GcodeCommand("G0"));
    instance.streamCommands();
    // When
    instance.responseMessage("error");
    // Then
    assertFalse(instance.isPaused());
}
Also used : Connection(com.willwinder.universalgcodesender.connection.Connection) GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) Test(org.junit.Test) GcodeStreamTest(com.willwinder.universalgcodesender.utils.GcodeStreamTest)

Example 45 with GcodeCommand

use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.

the class CommUtils method getSizeOfBuffer.

/**
 * Returns the number of characters in the list of GcodeCommands and adds
 * the length of the list representing one newline per command.
 *
 * Synchronized because this list is frequently modified through events,
 * especially at the beginning of a file transfer.
 */
public static synchronized int getSizeOfBuffer(List<GcodeCommand> list) {
    int characters = 0;
    GcodeCommand command;
    // Number of characters in list.
    Iterator<GcodeCommand> iter = list.iterator();
    while (iter.hasNext()) {
        command = iter.next();
        String next = command.getCommandString();
        // TODO: Carefully trace the newlines in commands and make sure
        // the GRBL_RX_BUFFER_SIZE is honored.
        // For now add a safety character to each command.
        characters += next.length() + 1;
    }
    return characters;
}
Also used : GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand)

Aggregations

GcodeCommand (com.willwinder.universalgcodesender.types.GcodeCommand)51 Test (org.junit.Test)26 GcodeStreamTest (com.willwinder.universalgcodesender.utils.GcodeStreamTest)19 IOException (java.io.IOException)11 Connection (com.willwinder.universalgcodesender.connection.Connection)4 Position (com.willwinder.universalgcodesender.model.Position)4 ControllerListener (com.willwinder.universalgcodesender.listeners.ControllerListener)3 GcodeStreamReader (com.willwinder.universalgcodesender.utils.GcodeStreamReader)3 File (java.io.File)3 LinkedList (java.util.LinkedList)3 GcodeParser (com.willwinder.universalgcodesender.gcode.GcodeParser)2 EasyMock.anyString (org.easymock.EasyMock.anyString)2 UnexpectedCommand (com.willwinder.universalgcodesender.AbstractController.UnexpectedCommand)1 GcodeMeta (com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta)1 ArcExpander (com.willwinder.universalgcodesender.gcode.processors.ArcExpander)1 CommentProcessor (com.willwinder.universalgcodesender.gcode.processors.CommentProcessor)1 LineSplitter (com.willwinder.universalgcodesender.gcode.processors.LineSplitter)1 M30Processor (com.willwinder.universalgcodesender.gcode.processors.M30Processor)1 MeshLeveler (com.willwinder.universalgcodesender.gcode.processors.MeshLeveler)1 Translator (com.willwinder.universalgcodesender.gcode.processors.Translator)1