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);
}
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());
}
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());
}
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());
}
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;
}
Aggregations