|
|
@ -31,11 +31,11 @@ EventHandlerResult FocusSerial::afterEachCycle() {
|
|
|
|
// If the serial buffer is empty, we don't have any work to do
|
|
|
|
// If the serial buffer is empty, we don't have any work to do
|
|
|
|
if (Runtime.serialPort().available() == 0) {
|
|
|
|
if (Runtime.serialPort().available() == 0) {
|
|
|
|
return EventHandlerResult::OK;
|
|
|
|
return EventHandlerResult::OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
command_[buf_cursor_++] = Runtime.serialPort().read();
|
|
|
|
command_[buf_cursor_++] = Runtime.serialPort().read();
|
|
|
|
} while ( command_[buf_cursor_ - 1] != SEPARATOR
|
|
|
|
} while (command_[buf_cursor_ - 1] != SEPARATOR
|
|
|
|
&& buf_cursor_ < sizeof(command_)
|
|
|
|
&& buf_cursor_ < sizeof(command_)
|
|
|
|
&& Runtime.serialPort().available()
|
|
|
|
&& Runtime.serialPort().available()
|
|
|
|
&& (Runtime.serialPort().peek() != NEWLINE));
|
|
|
|
&& (Runtime.serialPort().peek() != NEWLINE));
|
|
|
@ -48,17 +48,17 @@ EventHandlerResult FocusSerial::afterEachCycle() {
|
|
|
|
return EventHandlerResult::OK;
|
|
|
|
return EventHandlerResult::OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( (command_[buf_cursor_ - 1] != SEPARATOR) && (Runtime.serialPort().peek() != NEWLINE)
|
|
|
|
if ((command_[buf_cursor_ - 1] != SEPARATOR) && (Runtime.serialPort().peek() != NEWLINE)
|
|
|
|
&& buf_cursor_ < sizeof(command_)
|
|
|
|
&& buf_cursor_ < sizeof(command_)
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
// We don't have enough command to work with yet.
|
|
|
|
// We don't have enough command to work with yet.
|
|
|
|
// Let's leave the buffer around for another cycle
|
|
|
|
// Let's leave the buffer around for another cycle
|
|
|
|
return EventHandlerResult::OK;
|
|
|
|
return EventHandlerResult::OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If this was a command with a space-delimited payload,
|
|
|
|
// If this was a command with a space-delimited payload,
|
|
|
|
// strip the space delimiter off
|
|
|
|
// strip the space delimiter off
|
|
|
|
if ( (command_[buf_cursor_ - 1] == SEPARATOR) ) {
|
|
|
|
if ((command_[buf_cursor_ - 1] == SEPARATOR)) {
|
|
|
|
command_[buf_cursor_ - 1] = '\0';
|
|
|
|
command_[buf_cursor_ - 1] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|