评论
合作者
下面是对代码的详细解释: 加载阶段加载 gcode 时将过滤掉所有空行,该 const lines = gcode.split('\n')
.filter(line => (line.trim().length > 0));
this.state.lines = lines; // non-empty lines without "\n"
处理阶段如果 sp.line = sp.line || this.state.lines[this.state.sent].trim();
dataFilter 用于翻译一行中的表达式,在返回新行之前将删除 gcode 注释。请注意,转换后的过滤结果可能是一个空字符串。 if (this.dataFilter) {
sp.line = this.dataFilter(sp.line, this.state.context) || '';
}
实际上,这 // The newline character (\n) consumed the RX buffer space
if ((sp.line.length > 0) && ((sp.dataLength + (sp.line.length + 1)) >= sp.bufferSize)) {
break;
}
空行不会发出 this.state.sent++;
this.emit('change');
if (sp.line.length === 0) {
this.ack(); // ack empty line
continue;
}
const line = sp.line + '\n';
sp.line = '';
sp.dataLength += line.length;
sp.queue.push(line.length);
this.emit('data', line, this.state.context);
|
贡献者作者
明白了,谢谢。 |
我一直在尝试详细了解 Sender 和 Workflow 逻辑,并且发现了我认为可能是错误的地方。
在 Sender.js 中,我们有这样的代码:
如果 sp.line.length == 0,则跳过测试的其余部分,并继续发送。这对我来说似乎不正确。消耗 RX 缓冲区空间的空行加换行符在我看来与非空行加上消耗它的换行符一样。如果该解释是正确的,
(sp.line.length > 0) &&
则应删除该部分。