Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SITL: adjusted SITL tab (built-in serial receiver support) #1849

Merged
merged 5 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function createWindow() {
if (process.env.NODE_ENV === 'development') {
mainWindow.webContents.openDevTools();
}
}
};

app.on('window-all-closed', () => {

Expand Down
150 changes: 49 additions & 101 deletions js/sitl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,151 +8,73 @@ const { chmod, rm } = require('node:fs');
const { GUI } = require('./gui');

const serialRXProtocolls = [
{
name : "Flight Controller Proxy",
baudRate: 115200,
stopBits: "One",
parity: "None"
},
{
name : "SBus",
baudrate: 100000,
baudRate: 100000,
stopBits: "Two",
parity: "Even"
},
{
name : "SBus Fast",
baudrate: 200000,
baudRate: 200000,
stopBits: "Two",
parity: "Even"
},
{
name : "Crossfire/Ghost",
baudrate: 420000,
baudRate: 420000,
stopBits: "One",
parity: "None"
},
{
name : "FPort/IBus/Spektrum/SRXL2/SUMD",
baudrate: 115200,
baudRate: 115200,
stopBits: "One",
parity: "None"
},
{
name : "JETI EX Bus",
baudrate: 125000,
baudRate: 125000,
stopBits: "One",
parity: "None"
},
];

var Ser2TCP = {
var SitlSerialPortUtils = {

isRunning: false,
process: null,
portsList: [],
stopPolling: false,

getProtocolls: function() {
return serialRXProtocolls;
},

start: function(comPort, serialPortOptions, ipAddress, tcpPort, callback) {

if (this.isRunning)
this.stop();

var path;
if (GUI.operating_system == 'Windows') {
path = './../resources/sitl/windows/Ser2TCP.exe'
} else if (GUI.operating_system == 'Linux') {
path = './../resources/sitl/linux/Ser2TCP'
chmod(path, 0o755, (err) => {
if (err)
console.log(err);
});
} else if (GUI.operating_system == 'MacOS') {
path = './../resources/sitl/macos/Ser2TCP'
chmod(path, 0o755, (err) => {
if (err)
console.log(err);
});
} else {
alert(GUI.operating_system);
return;
}

var protocoll = serialRXProtocolls.find(proto => {
return proto.name == serialPortOptions.protocollName;
});

var args = [];
if (protocoll && protocoll.name != "manual") {
args.push(`--comport=${comPort}`)
args.push(`--baudrate=${protocoll.baudrate}`);
args.push(`--stopbits=${protocoll.stopBits}`)
args.push(`--parity=${protocoll.parity}`)
args.push(`--ip=${ipAddress}`);
args.push(`--tcpport=${tcpPort}`);
} else {
args.push(`--comport=${comPort}`)
args.push(`--baudrate${proserialPortOptionstocoll.baudrate}`);
args.push(`--stopbits=${protserialPortOptionsocoll.stopBits}`)
args.push(`--parity=${serialPortOptions.parity}`)
args.push(`--ip=${ipAddress}`);
args.push(`--tcpport=${tcpPort}`);
}

var opts = undefined;
if (GUI.operating_system == 'Linux')
opts = { useShell: true };

this.process = spawn(path, args, opts);
this.isRunning = true;

this.process.stdout.on('data', (data) => {
if (callback)
callback(data);
});

this.process.stderr.on('data', (data) => {
if (callback)
callback(data);
});

this.process.on('error', (error) => {
if (callback)
callback(error);
this.isRunning = false;
});

this.process.on('exit', () => {
if (this.isRunning)
this.spawn(path, args, callback);
});
},

stop: function() {
if (this.isRunning) {
this.isRunning = false;
this.process.kill();
}
},

getDevices: function(callback) {
SerialPort.list().then((ports, error) => {
var devices = [];
if (error) {
GUI.log("Unable to list serial ports.");
} else {
} else {
ports.forEach((device) => {
if (GUI.operating_system == 'Windows') {
var m = device.path.match(/COM\d?\d/g)
if (GUI.operating_system == 'Windows') {
var m = device.path.match(/COM\d?\d/g)
if (m)
devices.push(m[0]);
} else {
devices.push(m[0]);
} else {
/* Limit to: USB serial, RFCOMM (BT), 6 legacy devices */
if (device.pnpId ||
device.path.match(/rfcomm\d*/) ||
device.path.match(/ttyS[0-5]$/)) {
devices.push(device.path);
}
}
});
}
}
});
}
callback(devices);
});
Expand Down Expand Up @@ -209,7 +131,7 @@ var SITLProcess = {
});
},

start: function(eepromFileName, sim, useIMU, simIp, simPort, channelMap, callback) {
start: function(eepromFileName, sim, useIMU, simIp, simPort, channelMap, serialPortOptions, callback) {

if (this.isRunning)
this.stop();
Expand All @@ -232,7 +154,7 @@ var SITLProcess = {
if (err)
console.log(err);
});

} else {
alert(GUI.operating_system);
return;
Expand All @@ -255,6 +177,32 @@ var SITLProcess = {
if (channelMap)
args.push(`--chanmap=${channelMap}`)
}

if (serialPortOptions != null) {
var protocoll = serialRXProtocolls.find(proto => {
return proto.name == serialPortOptions.protocollName;
});

if (protocoll && protocoll.name != "manual") {
args.push(`--serialport=${serialPortOptions.serialPort}`)
args.push(`--baudrate=${protocoll.baudRate}`);
args.push(`--stopbits=${protocoll.stopBits}`)
args.push(`--parity=${protocoll.parity}`)
if ( protocoll.name == "Flight Controller Proxy") {
args.push(`--fcproxy`);
} else {
args.push(`--serialuart=${serialPortOptions.serialUart}`);
}
} else {
args.push(`--serialport=${serialPortOptions.serialPort}`)
args.push(`--baudrate=${serialPortOptions.baudRate}`);
args.push(`--stopbits=${serialPortOptions.stopBits}`)
args.push(`--parity=${serialPortOptions.parity}`)
args.push(`--serialuart=${serialPortOptions.serialUart}`);
}
}

callback( sitlExePath + " " + args.join(" ") + "\n");
this.spawn(sitlExePath, args, callback);
},

Expand Down Expand Up @@ -292,4 +240,4 @@ var SITLProcess = {
}
};

module.exports = { Ser2TCP, SITLProcess };
module.exports = { SITLProcess, SitlSerialPortUtils };
16 changes: 8 additions & 8 deletions locale/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,20 @@
"sitlStdProfileCantOverwritten": {
"message": "SITL standard profile can't be overwritten. Please create a new one."
},
"sitlSerialToTCP": {
"message": "Serial to TCP (UART)"
"serialReceiver": {
"message": "Serial receiver"
},
"sitlSerialProtocoll": {
"message": "Preset for RX Protocoll"
"message": "Serial port settings preset for RX Protocol of connected receiver"
},
"sitlSerialStopbits": {
"message": "Stopbits"
},
"sitlSerialPort": {
"message": "Serial port"
"message": "Serial receiver/Proxy FC is connectected to host's serial port"
},
"sitlSerialTCPPort": {
"message": "TCP port"
"sitlSerialUART": {
"message": "Serial receiver is configured on SITL's UART"
},
"sitlSerialParity": {
"message": "Parity"
Expand All @@ -277,8 +277,8 @@
"sitlPortHelp": {
"message": "Port number of the interface of the simulator. Note: The RealFlight port is fixed and cannot be changed."
},
"sitlSer2TcpHelp": {
"message": "Devices with a UART interface can be used with SITL via a serial to USB interface. Especially intended for serial receivers to use the full number of channels. "
"sitlSerialReceiverHelp": {
"message": "Use receiver (SBUS/CRSF/etc.) connected to host using USB-to-UART adapter or proxy Flight Controller."
},
"auxiliaryAcroEnabled": {
"message": "ACRO"
Expand Down
Loading
Loading