Work on mockserial

This commit is contained in:
Matt McWilliams 2024-07-11 23:01:44 -04:00
parent e44fc61106
commit 5a291aeca9
3 changed files with 38 additions and 6 deletions

17
dist/camera/index.js vendored
View File

@ -5,6 +5,21 @@ const log_1 = require("../log");
const delay_1 = require("../delay");
const serialport_1 = require("serialport");
const parser_readline_1 = require("@serialport/parser-readline");
class CameraSerialPortMock extends serialport_1.SerialPortMock {
constructor(options, openCallback = null) {
super(options, openCallback);
this.log = (0, log_1.createLog)('mock');
console.dir(this);
}
write(buffer) {
super.write(buffer);
this.log.info(`Received data: "${buffer}"`);
if (buffer === 'i') {
this.emit('i');
}
return true;
}
}
class Camera {
constructor() {
this.ready = false;
@ -97,7 +112,7 @@ class Camera {
this.port = '/dev/fake';
try {
serialport_1.SerialPortMock.binding.createPort(this.port);
this.serial = new serialport_1.SerialPortMock({
this.serial = new CameraSerialPortMock({
path: this.port,
baudRate: this.baud
});

File diff suppressed because one or more lines are too long

View File

@ -16,12 +16,30 @@ interface PortInfo {
vendorId: string | undefined;
}
class CameraSerialPortMock extends SerialPortMock {
private log : Logger;
constructor (options : any, openCallback : ErrorCallback = null) {
super(options, openCallback);
this.log = createLog('mock');
console.dir(this);
}
write (buffer : any) : boolean {
super.write(buffer)
this.log.info(`Received data: "${buffer}"`);
if (buffer === 'i') {
this.emit('i');
}
return true;
}
}
export class Camera {
private log : Logger;
private parser : ReadlineParser;
private ready : boolean = false;
private connected : boolean = false;
private serial : SerialPort | SerialPortMock = null;
private serial : SerialPort | CameraSerialPortMock = null;
private baud : number = 57600;
private next : Function = null;
private port : string = null;
@ -111,7 +129,7 @@ export class Camera {
this.port = '/dev/fake';
try {
SerialPortMock.binding.createPort(this.port);
this.serial = new SerialPortMock({
this.serial = new CameraSerialPortMock({
path : this.port,
baudRate: this.baud
});
@ -130,7 +148,6 @@ export class Camera {
return resolve(true);
});
}.bind(this));
}
private onData (data : string) {