Uint8List remain = Uint8List(0);
String utf8Log = "";
void stream2utf8(Uint8List data) {
final findLF = data.lastIndexWhere((e) => e == 0xa);// find position of the last \n
final endLF = findLF + 1; // to include LF
final len = remain.length + (findLF < 0 ? data.length : endLF);
final resemble = Uint8List(len);
if (remain.isNotEmpty) resemble.setAll(0, remain);// copy remain to front of resemble
resemble.setRange(remain.length, len, data); // append sublist of data to resemble
if (findLF < 0) { // keep in memory
remain = resemble;
} else { // line feed found, time to flush out
remain = Uint8List.sublistView(data, endLF);
Uint8List afterESC = Uint8List.sublistView(resemble);
while (afterESC.isNotEmpty) { // until empty
final findESC = afterESC.indexOf(0x1b); // find ESC position
utf8Log += utf8.decode(Uint8List.sublistView(afterESC, 0,
findESC < 0 ? afterESC.length : findESC
));
if (findESC < 0) break;
var lenESC = 1; // sequence ^[ ... m seek
if (afterESC[findESC + lenESC] == 0x5b) { // found sequence start '['
do {
lenESC ++; // one byte advance
if (afterESC[findESC + lenESC] == 0x6d) { // found end of character 'm'
lenESC ++;// one byte advance
break;
}
} while (findESC + lenESC < afterESC.length);
if (findESC + lenESC >= afterESC.length) { // todo: other ^[ sequence not yet implement!
afterESC[findESC] = 0x5E; // change ESC from 0x1b to '^' to prevent infinit loop
continue;// backoff to show this sequence
}
} else { // todo: other ^ sequence not yet implement!
afterESC[findESC] = 0x5E; // change ESC from 0x1b to '^' to prevent infinit loop
continue;// backoff to show this sequence
}
afterESC = Uint8List.sublistView(afterESC, findESC + lenESC);// ok, go ahead
}
setState((){}); // update screen if necessary
}
訂閱:
張貼留言 (Atom)
使用 pcie 轉接器連接 nvme SSD
之前 AM4 主機板使用 pcie ssd, 但主機板故障了沒辦法上網, 只好翻出以前買的 FM2 舊主機板, 想辦法讓老主機復活, 但舊主機板沒有 nvme 的界面, 因此上網買了 pcie 轉接器用來連接 nvme ssd, 遺憾的是 grub2 bootloader 無法識...
-
市面上便宜的時鐘, 內部機芯大多使用晶體振盪器產生固定頻率的脈沖去驅動 Lavet-type 步進馬達, 它只要一個 1.5V 電池就足以推動, 而馬達扭力主要是靠線圈內的電流產生磁力所致, 因此電流才是動力來源. 電壓太高會造成線圈電流飽和導致發熱,可能影響震盪頻率甚至燒毀...
-
參考資料: https://developer.android.com/training/connect-devices-wirelessly/nsd linux mint 上針對區域網路的名稱服務協定可以使用 avahi, 透過 avahi-browse -a -r 就能...
沒有留言:
張貼留言