我使用库创建了一个终端仿真器,使用另一个库连接到串行设备,这会将数据返回到我的终端。我可以在日志中看到,每次我在终端中写入一个字符并通过串行发送它时,都会返回以下三个字符以及正确的一个字符。☐[J. 当写入终端时,这些字符现在会显示出来。它们以某种方式在此代码中处理,但我不确定哪一部分,也许doEscRightSquareBracket
:
private void process(byte b, boolean doUTF8) {
// Let the UTF-8 decoder try to handle it if we're in UTF-8 mode
if (doUTF8 && mUTF8Mode && handleUTF8Sequence(b)) {
return;
}
// Handle C1 control characters
if ((b & 0x80) == 0x80 && (b & 0x7f) <= 0x1f) {
/* ESC ((code & 0x7f) + 0x40) is the two-byte escape sequence
corresponding to a particular C1 code */
process((byte) 27, false);
process((byte) ((b & 0x7f) + 0x40), false);
return;
}
switch (b) {
case 0: // NUL
// Do nothing
break;
case 7: // BEL
/* If in an OSC sequence, BEL may terminate a string; otherwise do
* nothing */
if (mEscapeState == ESC_RIGHT_SQUARE_BRACKET) {
doEscRightSquareBracket(b);
}
break;
case 8: // BS
setCursorCol(Math.max(0, mCursorCol - 1));
break;
case 9: // HT
// Move to next tab stop, but not past edge of screen
setCursorCol(nextTabStop(mCursorCol));
break;
case 13:
setCursorCol(0);
break;
case 10: // CR
case 11: // VT
case 12: // LF
doLinefeed();
break;
case 14: // SO:
setAltCharSet(true);
break;
case 15: // SI:
setAltCharSet(false);
break;
case 24: // CAN
case 26: // SUB
if (mEscapeState != ESC_NONE) {
mEscapeState = ESC_NONE;
emit((byte) 127);
}
break;
case 27: // ESC
// Starts an escape sequence unless we're parsing a string
if (mEscapeState != ESC_RIGHT_SQUARE_BRACKET) {
startEscapeSequence(ESC);
} else {
doEscRightSquareBracket(b);
}
break;
default:
mContinueSequence = false;
switch (mEscapeState) {
case ESC_NONE:
if (b >= 32) {
emit(b);
}
break;
case ESC:
doEsc(b);
break;
case ESC_POUND:
doEscPound(b);
break;
case ESC_SELECT_LEFT_PAREN:
doEscSelectLeftParen(b);
break;
case ESC_SELECT_RIGHT_PAREN:
doEscSelectRightParen(b);
break;
case ESC_LEFT_SQUARE_BRACKET:
doEscLeftSquareBracket(b); // CSI
break;
case ESC_LEFT_SQUARE_BRACKET_QUESTION_MARK:
doEscLSBQuest(b); // CSI ?
break;
case ESC_PERCENT:
doEscPercent(b);
break;
case ESC_RIGHT_SQUARE_BRACKET:
doEscRightSquareBracket(b);
break;
case ESC_RIGHT_SQUARE_BRACKET_ESC:
doEscRightSquareBracketEsc(b);
break;
default:
unknownSequence(b);
break;
}
if (!mContinueSequence) {
mEscapeState = ESC_NONE;
}
break;
}
}
这不是终端的问题,因为它正在过滤它。但现在我想将返回的数据写入 editText 并且正在写入奇数字符。他们是什么,我该如何阻止他们?它们一定是终端过滤掉它们时可能发生的一些正常情况?当我输入 exit 时,您可以在此处看到它,它应该在右侧镜像: