Skip to content

Commit d689e3d

Browse files
committed
[SITl] Fix serial selection and executable name on Linux
1 parent 4ecf58a commit d689e3d

File tree

2 files changed

+44
-39
lines changed

2 files changed

+44
-39
lines changed

js/sitl.js

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ var Ser2TCP = {
4949
},
5050

5151
start: function(comPort, serialPortOptions, ipAddress, tcpPort, callback) {
52-
52+
5353
if (this.isRunning)
5454
this.stop();
55-
55+
5656
var path;
5757
if (GUI.operating_system == 'Windows') {
5858
path = './resources/sitl/windows/Ser2TCP.exe'
5959
} else if (GUI.operating_system == 'Linux') {
60-
path = './resources/sitl/linux/ser2TCP'
60+
path = './resources/sitl/linux/Ser2TCP'
6161
chmod(path, 0o755, (err) => {
6262
if (err)
6363
console.log(err);
@@ -69,7 +69,7 @@ var Ser2TCP = {
6969
var protocoll = serialRXProtocolls.find(proto => {
7070
return proto.name == serialPortOptions.protocollName;
7171
});
72-
72+
7373
var args = [];
7474
if (protocoll && protocoll.name != "manual") {
7575
args.push(`--comport=${comPort}`)
@@ -85,15 +85,15 @@ var Ser2TCP = {
8585
args.push(`--parity=${serialPortOptions.parity}`)
8686
args.push(`--ip=${ipAddress}`);
8787
args.push(`--tcpport=${tcpPort}`);
88-
}
88+
}
8989

9090
var opts = undefined;
91-
if (GUI.operating_system == 'Linux')
91+
if (GUI.operating_system == 'Linux')
9292
opts = { useShell: true };
93-
93+
9494
this.process = spawn(path, args, opts);
9595
this.isRunning = true;
96-
96+
9797
this.process.stdout.on('data', (data) => {
9898
if (callback)
9999
callback(data);
@@ -109,7 +109,7 @@ var Ser2TCP = {
109109
callback(error);
110110
this.isRunning = false;
111111
});
112-
112+
113113
this.process.on('exit', () => {
114114
if (this.isRunning)
115115
this.spawn(path, args, callback);
@@ -119,27 +119,32 @@ var Ser2TCP = {
119119
stop: function() {
120120
if (this.isRunning) {
121121
this.isRunning = false;
122-
this.process.kill();
123-
}
122+
this.process.kill();
123+
}
124124
},
125125

126126
getDevices: function(callback) {
127127
chrome.serial.getDevices((devices_array) => {
128128
var devices = [];
129129
devices_array.forEach((device) => {
130-
131-
if (GUI.operating_system == 'Windows') {
130+
131+
if (GUI.operating_system == 'Windows') {
132132
var m = device.path.match(/COM\d?\d/g)
133133
if (m)
134134
devices.push(m[0]);
135-
} else
136-
devices.push(device.displayName);
135+
} else {
136+
if (device.displayName != null) {
137+
var m = device.path.match(/\/dev\/.*/)
138+
if (m)
139+
devices.push(m[0]);
140+
}
141+
}
137142
});
138143
callback(devices);
139144
});
140145
},
141146

142-
pollSerialPorts: function(callback) {
147+
pollSerialPorts: function(callback) {
143148
this.getDevices(devices => {
144149
if (!this.arraysEqual(this.portsList, devices)) {
145150
this.portsList = devices;
@@ -149,7 +154,7 @@ var Ser2TCP = {
149154

150155
});
151156
if (!this.stopPolling) {
152-
setTimeout(() => { this.pollSerialPorts(callback) }, 250);
157+
setTimeout(() => { this.pollSerialPorts(callback) }, 250);
153158
} else {
154159
this.stopPolling = false;
155160
}
@@ -168,7 +173,7 @@ var Ser2TCP = {
168173
if (a === b) return true;
169174
if (a == null || b == null) return false;
170175
if (a.length !== b.length) return false;
171-
176+
172177
for (var i = 0; i < a.length; ++i) {
173178
if (a[i] !== b[i]) return false;
174179
}
@@ -177,7 +182,7 @@ var Ser2TCP = {
177182
}
178183

179184
var SITLProcess = {
180-
185+
181186
spawn : null,
182187
isRunning: false,
183188
process: null,
@@ -194,7 +199,7 @@ var SITLProcess = {
194199

195200
if (this.isRunning)
196201
this.stop();
197-
202+
198203
var sitlExePath, eepromPath;
199204
if (GUI.operating_system == 'Windows') {
200205
sitlExePath = './resources/sitl/windows/inav_SITL.exe'
@@ -209,36 +214,36 @@ var SITLProcess = {
209214
} else {
210215
return;
211216
}
212-
217+
213218
var args = [];
214219
args.push(`--path=${eepromPath}`);
215220

216221
if (sim) {
217-
args.push(`--sim=${sim}`);
218-
if (useIMU)
222+
args.push(`--sim=${sim}`);
223+
if (useIMU)
219224
args.push("--useimu")
220-
221-
if (simIp)
225+
226+
if (simIp)
222227
args.push(`--simip=${simIp}`);
223-
224-
if (simPort)
228+
229+
if (simPort)
225230
args.push(`--simport=${simPort}`);
226-
231+
227232
if (channelMap)
228233
args.push(`--chanmap=${channelMap}`)
229-
}
230-
this.spawn(sitlExePath, args, callback);
234+
}
235+
this.spawn(sitlExePath, args, callback);
231236
},
232237

233238
spawn: function(path, args, callback) {
234-
239+
235240
var opts = undefined;
236-
if (GUI.operating_system == 'Linux')
241+
if (GUI.operating_system == 'Linux')
237242
opts = { useShell: true };
238-
243+
239244
this.process = spawn(path, args, opts);
240245
this.isRunning = true;
241-
246+
242247
this.process.stdout.on('data', (data) => {
243248
if (callback)
244249
callback(data);
@@ -259,7 +264,7 @@ var SITLProcess = {
259264
stop: function() {
260265
if (this.isRunning) {
261266
this.isRunning = false;
262-
this.process.kill();
263-
}
267+
this.process.kill();
268+
}
264269
}
265-
};
270+
};

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)