Skip to content

Instantly share code, notes, and snippets.

@winder
Created July 25, 2012 13:24
Show Gist options
  • Save winder/3176177 to your computer and use it in GitHub Desktop.
Save winder/3176177 to your computer and use it in GitHub Desktop.
Skipping empty lines
void streamFileCommands() {
boolean skip;
// Keep sending commands until the last command is sent, or the
// character buffer is full.
while ((this.commandBuffer.currentCommand().isSent() == false) &&
CommUtils.checkRoomInBuffer(this.activeCommandList, this.commandBuffer.currentCommand())) {
skip = false;
GcodeCommand command = this.commandBuffer.currentCommand();
// Allow a command preprocessor listener to preprocess the command.
if (this.commandPreprocessorListener != null) {
String processed = this.commandPreprocessorListener.preprocessCommand(command.getCommandString());
command.setCommand(processed);
if (processed.trim().equals("")) {
skip = true;
}
}
// Don't send skipped commands.
if (!skip) {
command.setSent(true);
this.activeCommandList.add(command);
// Commands parsed by the buffer list have embedded newlines.
this.sendStringToComm(command.getCommandString());
}
if (this.commandSentListener != null) {
this.commandCompleteListener.commandSent(command);
}
// If the command was skipped let the listeners know.
if (skip) {
this.sendMessageToConsoleListener("Skipping command #"
+ command.getCommandNumber());
command.setResponse("<skipped by application>");
if (this.commandCompleteListener != null) {
this.commandCompleteListener.commandComplete(command);
}
}
// Load the next command.
if (this.commandBuffer.hasNext()) {
this.commandBuffer.nextCommand();
}
}
// If the final response is done... wrap up.
if (this.commandBuffer.getFinalCommand().isDone()) {
this.finishStreamFileToComm();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment