Skip to content

Commit

Permalink
Merge pull request #1766 from stronnag/jh_fix_linux_ser2tcp
Browse files Browse the repository at this point in the history
[SITl] Fix serial selection and executable name on Linux
  • Loading branch information
DzikuVx authored May 11, 2023
2 parents a08920b + d689e3d commit 25a7308
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 39 deletions.
79 changes: 42 additions & 37 deletions js/sitl.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ var Ser2TCP = {
},

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'
path = './resources/sitl/linux/Ser2TCP'
chmod(path, 0o755, (err) => {
if (err)
console.log(err);
Expand All @@ -69,7 +69,7 @@ var Ser2TCP = {
var protocoll = serialRXProtocolls.find(proto => {
return proto.name == serialPortOptions.protocollName;
});

var args = [];
if (protocoll && protocoll.name != "manual") {
args.push(`--comport=${comPort}`)
Expand All @@ -85,15 +85,15 @@ var Ser2TCP = {
args.push(`--parity=${serialPortOptions.parity}`)
args.push(`--ip=${ipAddress}`);
args.push(`--tcpport=${tcpPort}`);
}
}

var opts = undefined;
if (GUI.operating_system == 'Linux')
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);
Expand All @@ -109,7 +109,7 @@ var Ser2TCP = {
callback(error);
this.isRunning = false;
});

this.process.on('exit', () => {
if (this.isRunning)
this.spawn(path, args, callback);
Expand All @@ -119,27 +119,32 @@ var Ser2TCP = {
stop: function() {
if (this.isRunning) {
this.isRunning = false;
this.process.kill();
}
this.process.kill();
}
},

getDevices: function(callback) {
chrome.serial.getDevices((devices_array) => {
var devices = [];
devices_array.forEach((device) => {
if (GUI.operating_system == 'Windows') {

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);
} else {
if (device.displayName != null) {
var m = device.path.match(/\/dev\/.*/)
if (m)
devices.push(m[0]);
}
}
});
callback(devices);
});
},

pollSerialPorts: function(callback) {
pollSerialPorts: function(callback) {
this.getDevices(devices => {
if (!this.arraysEqual(this.portsList, devices)) {
this.portsList = devices;
Expand All @@ -149,7 +154,7 @@ var Ser2TCP = {

});
if (!this.stopPolling) {
setTimeout(() => { this.pollSerialPorts(callback) }, 250);
setTimeout(() => { this.pollSerialPorts(callback) }, 250);
} else {
this.stopPolling = false;
}
Expand All @@ -168,7 +173,7 @@ var Ser2TCP = {
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;
}
Expand All @@ -177,7 +182,7 @@ var Ser2TCP = {
}

var SITLProcess = {

spawn : null,
isRunning: false,
process: null,
Expand All @@ -194,7 +199,7 @@ var SITLProcess = {

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

var sitlExePath, eepromPath;
if (GUI.operating_system == 'Windows') {
sitlExePath = './resources/sitl/windows/inav_SITL.exe'
Expand All @@ -209,36 +214,36 @@ var SITLProcess = {
} else {
return;
}

var args = [];
args.push(`--path=${eepromPath}`);

if (sim) {
args.push(`--sim=${sim}`);
if (useIMU)
args.push(`--sim=${sim}`);
if (useIMU)
args.push("--useimu")
if (simIp)

if (simIp)
args.push(`--simip=${simIp}`);
if (simPort)

if (simPort)
args.push(`--simport=${simPort}`);

if (channelMap)
args.push(`--chanmap=${channelMap}`)
}
this.spawn(sitlExePath, args, callback);
}
this.spawn(sitlExePath, args, callback);
},

spawn: function(path, args, callback) {

var opts = undefined;
if (GUI.operating_system == 'Linux')
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);
Expand All @@ -259,7 +264,7 @@ var SITLProcess = {
stop: function() {
if (this.isRunning) {
this.isRunning = false;
this.process.kill();
}
this.process.kill();
}
}
};
};
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 25a7308

Please sign in to comment.