flush out serial data when too long (#375)
This commit is contained in:
parent
684646d3de
commit
1f2027d0f9
@ -93,7 +93,7 @@ namespace pxsim {
|
||||
break;
|
||||
case "serial":
|
||||
let data = (<SimulatorSerialMessage>msg).data || "";
|
||||
this.serialState.recieveData(data);
|
||||
this.serialState.receiveData(data);
|
||||
break;
|
||||
case "radiopacket":
|
||||
let packet = <SimulatorRadioPacketMessage>msg;
|
||||
|
@ -1,8 +1,9 @@
|
||||
namespace pxsim {
|
||||
const SERIAL_BUFFER_LENGTH = 16;
|
||||
export class SerialState {
|
||||
serialIn: string[] = [];
|
||||
|
||||
public recieveData(data: string) {
|
||||
public receiveData(data: string) {
|
||||
this.serialIn.push();
|
||||
}
|
||||
|
||||
@ -13,18 +14,15 @@ namespace pxsim {
|
||||
|
||||
serialOutBuffer: string = "";
|
||||
writeSerial(s: string) {
|
||||
for (let i = 0; i < s.length; ++i) {
|
||||
let c = s[i];
|
||||
this.serialOutBuffer += c;
|
||||
if (c == "\n") {
|
||||
Runtime.postMessage(<SimulatorSerialMessage>{
|
||||
type: "serial",
|
||||
data: this.serialOutBuffer,
|
||||
id: runtime.id
|
||||
})
|
||||
this.serialOutBuffer = ""
|
||||
break;
|
||||
}
|
||||
this.serialOutBuffer += s;
|
||||
if (/\n/.test(this.serialOutBuffer) || this.serialOutBuffer.length > SERIAL_BUFFER_LENGTH) {
|
||||
Runtime.postMessage(<SimulatorSerialMessage>{
|
||||
type: 'serial',
|
||||
data: this.serialOutBuffer,
|
||||
id: runtime.id,
|
||||
sim: true
|
||||
})
|
||||
this.serialOutBuffer = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user