mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-24 16:55:22 +03:00
Firmware flasher, BLE, TCP, UDP -> Electron
This commit is contained in:
parent
2f880e218d
commit
7df8253099
36 changed files with 733 additions and 656 deletions
|
@ -16,23 +16,6 @@ class ConnectionSerial extends Connection {
|
|||
connectImplementation(path, options, callback) {
|
||||
try {
|
||||
this._serialport = new SerialPortStream({binding, path: path, baudRate: options.bitrate, autoOpen: true}, () => {
|
||||
|
||||
this._serialport.on('data', buffer => {
|
||||
this._onReceiveListeners.forEach(listener => {
|
||||
listener({
|
||||
connectionId: this._connectionId,
|
||||
data: buffer
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
this._serialport.on('error', error => {
|
||||
console.log("Serial error: " + error);
|
||||
this._onReceiveErrorListeners.forEach(listener => {
|
||||
listener(error);
|
||||
});
|
||||
});
|
||||
|
||||
if (callback) {
|
||||
callback({
|
||||
connectionId: ++this._connectionId,
|
||||
|
@ -44,6 +27,27 @@ class ConnectionSerial extends Connection {
|
|||
console.log(error);
|
||||
callback(false);
|
||||
}
|
||||
|
||||
this._serialport.on('data', buffer => {
|
||||
this._onReceiveListeners.forEach(listener => {
|
||||
listener({
|
||||
connectionId: this._connectionId,
|
||||
data: buffer
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
this._serialport.on('close', error => {
|
||||
this.abort();
|
||||
});
|
||||
|
||||
this._serialport.on('error', error => {
|
||||
this.abort();
|
||||
console.log("Serial error: " + error);
|
||||
this._onReceiveErrorListeners.forEach(listener => {
|
||||
listener(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
disconnectImplementation(callback) {
|
||||
|
@ -52,24 +56,27 @@ class ConnectionSerial extends Connection {
|
|||
if (error) {
|
||||
console.log("Unable to close serial: " + error)
|
||||
}
|
||||
if (callback) {
|
||||
callback(error ? false : true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(true);
|
||||
}
|
||||
}
|
||||
|
||||
sendImplementation(data, callback) {
|
||||
if (this._serialport && this._serialport.isOpen) {
|
||||
this._serialport.write(Buffer.from(data), error => {
|
||||
var result = 0;
|
||||
var sent = data.byteLength;
|
||||
if (error) {
|
||||
result = 1;
|
||||
sent = 0;
|
||||
console.log("Serial wrire error: " + error)
|
||||
}
|
||||
if (callback) {
|
||||
callback({
|
||||
bytesSent: data.byteLength,
|
||||
bytesSent: sent,
|
||||
resultCode: result
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue