mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-14 11:59:51 +03:00
Merge pull request #1738 from Scavanger/SITL-Integration
SITL integration
This commit is contained in:
commit
448d9dc3ba
26 changed files with 6597 additions and 5710 deletions
3
js/fc.js
3
js/fc.js
|
@ -596,7 +596,8 @@ var FC = {
|
|||
'NMEA',
|
||||
'UBLOX',
|
||||
'UBLOX7',
|
||||
'MSP'
|
||||
'MSP',
|
||||
'FAKE'
|
||||
];
|
||||
},
|
||||
getGpsBaudRates: function () {
|
||||
|
|
|
@ -14,6 +14,7 @@ var GUI_control = function () {
|
|||
'landing',
|
||||
'firmware_flasher',
|
||||
'mission_control',
|
||||
'sitl',
|
||||
'help'
|
||||
];
|
||||
this.defaultAllowedTabsWhenConnected = [
|
||||
|
|
|
@ -69,7 +69,7 @@ PortHandler.check = function () {
|
|||
chrome.storage.local.get('last_used_port', function (result) {
|
||||
// if last_used_port was set, we try to select it
|
||||
if (result.last_used_port) {
|
||||
if (result.last_used_port == "ble" || result.last_used_port == "tcp" || result.last_used_port == "udp") {
|
||||
if (result.last_used_port == "ble" || result.last_used_port == "tcp" || result.last_used_port == "udp" || result.last_used_port == "sitl" || result.last_used_port == "sitl-demo") {
|
||||
$('#port').val(result.last_used_port);
|
||||
} else {
|
||||
current_ports.forEach(function(port) {
|
||||
|
@ -184,6 +184,8 @@ PortHandler.update_port_select = function (ports) {
|
|||
$('div#port-picker #port').append($("<option/>", {value: 'ble', text: 'BLE', data: {isBle: true}}));
|
||||
$('div#port-picker #port').append($("<option/>", {value: 'tcp', text: 'TCP', data: {isTcp: true}}));
|
||||
$('div#port-picker #port').append($("<option/>", {value: 'udp', text: 'UDP', data: {isUdp: true}}));
|
||||
$('div#port-picker #port').append($("<option/>", {value: 'sitl', text: 'SITL', data: {isSitl: true}}));
|
||||
$('div#port-picker #port').append($("<option/>", {value: 'sitl-demo', text: 'Demo mode', data: {isSitl: true}}));
|
||||
};
|
||||
|
||||
PortHandler.port_detected = function(name, code, timeout, ignore_timeout) {
|
||||
|
|
|
@ -5,7 +5,8 @@ $(document).ready(function () {
|
|||
|
||||
var $port = $('#port'),
|
||||
$baud = $('#baud'),
|
||||
$portOverride = $('#port-override');
|
||||
$portOverride = $('#port-override'),
|
||||
isDemoRunning = false;
|
||||
|
||||
/*
|
||||
* Handle "Wireless" mode with strict queueing of messages
|
||||
|
@ -89,14 +90,14 @@ $(document).ready(function () {
|
|||
$('#port-override-label').text("Port");
|
||||
}
|
||||
|
||||
if (selected_port.data().isDFU || selected_port.data().isBle || selected_port.data().isTcp || selected_port.data().isUdp) {
|
||||
if (selected_port.data().isDFU || selected_port.data().isBle || selected_port.data().isTcp || selected_port.data().isUdp || selected_port.data().isSitl) {
|
||||
$baud.hide();
|
||||
}
|
||||
else {
|
||||
$baud.show();
|
||||
}
|
||||
|
||||
if (selected_port.data().isBle || selected_port.data().isTcp || selected_port.data().isUdp) {
|
||||
if (selected_port.data().isBle || selected_port.data().isTcp || selected_port.data().isUdp || selected_port.data().isSitl) {
|
||||
$('.tab_firmware_flasher').hide();
|
||||
} else {
|
||||
$('.tab_firmware_flasher').show();
|
||||
|
@ -104,7 +105,7 @@ $(document).ready(function () {
|
|||
var type = ConnectionType.Serial;
|
||||
if (selected_port.data().isBle) {
|
||||
type = ConnectionType.BLE;
|
||||
} else if (selected_port.data().isTcp) {
|
||||
} else if (selected_port.data().isTcp || selected_port.data().isSitl) {
|
||||
type = ConnectionType.TCP;
|
||||
} else if (selected_port.data().isUdp) {
|
||||
type = ConnectionType.UDP;
|
||||
|
@ -150,10 +151,24 @@ $(document).ready(function () {
|
|||
|
||||
if (selected_port == 'tcp' || selected_port == 'udp') {
|
||||
CONFIGURATOR.connection.connect($portOverride.val(), {}, onOpen);
|
||||
} else if (selected_port == 'sitl') {
|
||||
CONFIGURATOR.connection.connect("127.0.0.1:5760", {}, onOpen);
|
||||
} else if (selected_port == 'sitl-demo') {
|
||||
if (SITLProcess.isRunning) {
|
||||
SITLProcess.stop();
|
||||
}
|
||||
SITLProcess.start("demo.bin");
|
||||
this.isDemoRunning = true;
|
||||
CONFIGURATOR.connection.connect("127.0.0.1:5760", {}, onOpen);
|
||||
} else {
|
||||
CONFIGURATOR.connection.connect(selected_port, {bitrate: selected_baud}, onOpen);
|
||||
}
|
||||
} else {
|
||||
if (this.isDemoRunning) {
|
||||
SITLProcess.stop();
|
||||
this.isDemoRunning = false;
|
||||
}
|
||||
|
||||
var wasConnected = CONFIGURATOR.connectionValid;
|
||||
|
||||
helper.timeout.killAll();
|
||||
|
|
270
js/sitl.js
Normal file
270
js/sitl.js
Normal file
|
@ -0,0 +1,270 @@
|
|||
'use strict'
|
||||
|
||||
const { spawn } = require('node:child_process');
|
||||
const pathMod = require('path');
|
||||
const { chmod, rm } = require('node:fs');
|
||||
|
||||
const serialRXProtocolls = [
|
||||
{
|
||||
name : "SBus",
|
||||
baudrate: 100000,
|
||||
stopBits: "Two",
|
||||
parity: "Even"
|
||||
},
|
||||
{
|
||||
name : "SBus Fast",
|
||||
baudrate: 200000,
|
||||
stopBits: "Two",
|
||||
parity: "Even"
|
||||
},
|
||||
{
|
||||
name : "Crossfire/Ghost",
|
||||
baudrate: 420000,
|
||||
stopBits: "One",
|
||||
parity: "None"
|
||||
},
|
||||
{
|
||||
name : "FPort/IBus/Spektrum/SRXL2/SUMD",
|
||||
baudrate: 115200,
|
||||
stopBits: "One",
|
||||
parity: "None"
|
||||
},
|
||||
{
|
||||
name : "JETI EX Bus",
|
||||
baudrate: 125000,
|
||||
stopBits: "One",
|
||||
parity: "None"
|
||||
},
|
||||
];
|
||||
|
||||
var Ser2TCP = {
|
||||
|
||||
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 {
|
||||
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) {
|
||||
chrome.serial.getDevices((devices_array) => {
|
||||
var devices = [];
|
||||
devices_array.forEach((device) => {
|
||||
|
||||
if (GUI.operating_system == 'Windows') {
|
||||
var m = device.path.match(/COM\d?\d/g)
|
||||
if (m)
|
||||
devices.push(m[0]);
|
||||
} else
|
||||
devices.push(device.displayName);
|
||||
});
|
||||
callback(devices);
|
||||
});
|
||||
},
|
||||
|
||||
pollSerialPorts: function(callback) {
|
||||
this.getDevices(devices => {
|
||||
if (!this.arraysEqual(this.portsList, devices)) {
|
||||
this.portsList = devices;
|
||||
if (callback)
|
||||
callback(this.portsList);
|
||||
}
|
||||
|
||||
});
|
||||
if (!this.stopPolling) {
|
||||
setTimeout(() => { this.pollSerialPorts(callback) }, 250);
|
||||
} else {
|
||||
this.stopPolling = false;
|
||||
}
|
||||
},
|
||||
|
||||
resetPortsList: function() {
|
||||
this.portsList = [];
|
||||
},
|
||||
|
||||
stopPollSerialPorts: function()
|
||||
{
|
||||
this.stopPolling = true;
|
||||
},
|
||||
|
||||
arraysEqual: function(a, b) {
|
||||
if (a === b) return true;
|
||||
if (a == null || b == null) return false;
|
||||
if (a.length !== b.length) return false;
|
||||
|
||||
for (var i = 0; i < a.length; ++i) {
|
||||
if (a[i] !== b[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
var SITLProcess = {
|
||||
|
||||
spawn : null,
|
||||
isRunning: false,
|
||||
process: null,
|
||||
|
||||
deleteEepromFile(filename) {
|
||||
rm(`${nw.App.dataPath}/${filename}`, error => {
|
||||
if (error) {
|
||||
GUI.log(`Unable to reset Demo mode: ${error.message}`);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
start: function(eepromFileName, sim, useIMU, simIp, simPort, channelMap, callback) {
|
||||
|
||||
if (this.isRunning)
|
||||
this.stop();
|
||||
|
||||
var sitlExePath, eepromPath;
|
||||
if (GUI.operating_system == 'Windows') {
|
||||
sitlExePath = './resources/sitl/windows/inav_SITL.exe'
|
||||
eepromPath = `${nw.App.dataPath}\\${eepromFileName}`
|
||||
} else if (GUI.operating_system == 'Linux') {
|
||||
sitlExePath = './resources/sitl/linux/inav_SITL';
|
||||
eepromPath = `${nw.App.dataPath}/${eepromFileName}`
|
||||
chmod(sitlExePath, 0o755, err => {
|
||||
if (err)
|
||||
console.log(err);
|
||||
});
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
var args = [];
|
||||
args.push(`--path=${eepromPath}`);
|
||||
|
||||
if (sim) {
|
||||
args.push(`--sim=${sim}`);
|
||||
if (useIMU)
|
||||
args.push("--useimu")
|
||||
|
||||
if (simIp)
|
||||
args.push(`--simip=${simIp}`);
|
||||
|
||||
if (simPort)
|
||||
args.push(`--simport=${simPort}`);
|
||||
|
||||
if (channelMap)
|
||||
args.push(`--chanmap=${channelMap}`)
|
||||
}
|
||||
this.spawn(sitlExePath, args, callback);
|
||||
},
|
||||
|
||||
spawn: function(path, args, callback) {
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue