Skip to content

Commit 1558496

Browse files
authored
Merge pull request #337 from MatzElectronics/solo-200-resubmit-G-launcherEncodingDifferences
Solo 200 resubmit G - Handle differences in encoding between launcher versions
2 parents fc53d9f + 515cf38 commit 1558496

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

Diff for: src/blocklypropclient.js

+21-11
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ var clientService = {
6666
path: 'localhost', // Is this always localhost?
6767
port: 6009, // BlocklyProp Client/Launcher port number
6868
type: null, // {string} Seems to be one of "", "ws", "http"
69-
70-
/*
7169
rxBase64: true,
70+
/*
7271
portListReceiveCountUp: 0, // This is set to 0 each time the port list is received, and incremented once each 4 second heartbeat
7372
activeConnection: null,
7473
*/
@@ -140,8 +139,8 @@ var find_client = function () {
140139
}
141140
};
142141

143-
var setPropToolbarButtons = function (ui_btn_state) {
144-
if (ui_btn_state === 'available') {
142+
var setPropToolbarButtons = function () {
143+
if (clientService.available) {
145144
if (projectData && projectData.board === 's3') {
146145
// Hide the buttons that are not required for the S3 robot
147146
$('.no-s3').addClass('hidden');
@@ -209,11 +208,12 @@ var check_client = function () {
209208
if (!data.server || data.server !== 'BlocklyPropHTTP') {
210209
client_version_str = '0.0.0';
211210
}
211+
212212
checkClientVersionModal(client_version_str);
213213

214214
clientService.type = 'http';
215215
clientService.available = true;
216-
setPropToolbarButtons('available');
216+
setPropToolbarButtons();
217217
if (checkForComPorts && typeof (checkForComPorts) === "function") {
218218
checkForComPorts();
219219
check_com_ports_interval = setInterval(checkForComPorts, 5000);
@@ -226,7 +226,7 @@ var check_client = function () {
226226
clientService.type = 'none';
227227
clientService.available = false;
228228
clientService.portsAvailable = false;
229-
setPropToolbarButtons('unavailable');
229+
setPropToolbarButtons();
230230
check_ws_socket_timeout = setTimeout(find_client, 3000);
231231
});
232232
};
@@ -342,14 +342,14 @@ function establish_socket() {
342342
if (ws_msg.type === 'hello-client') {
343343
// type: 'hello-client',
344344
// version: [String version (semantic versioning)]
345+
// rxBase64: [boolean, accepts base64-encoded serial streams (all versions transmit base64)]
345346
checkClientVersionModal(ws_msg.version);
346347

347348
if (window.getURLParameter('debug')) {
348349
console.log("Websocket client/launcher found - version " + ws_msg.version);
349350
}
350351

351-
// TODO: Add version checking here.
352-
352+
clientService.rxBase64 = ws_msg.rxBase64 || false;
353353
clientService.type = 'ws';
354354
clientService.available = true;
355355

@@ -383,12 +383,22 @@ function establish_socket() {
383383
// type: 'serial-terminal'
384384
// msg: [String Base64-encoded message]
385385

386-
var msg_in = atob(ws_msg.msg);
386+
var msg_in = '';
387+
try {
388+
var msg_in = atob(ws_msg.msg);
389+
} catch (error) {
390+
// only show the error if it's something other than base-64 encoding
391+
if (error.toString().indexOf("'atob'") < 0) {
392+
console.error(error);
393+
}
394+
msg_in = ws_msg.msg;
395+
}
396+
387397

388-
if (term !== null) { // is the terminal open?
398+
if (term !== null && msg_in !== '' && ws_msg.packetID) { // is the terminal open?
389399
pTerm.display(msg_in);
390400
pTerm.focus();
391-
} else if (graph !== null) { // is the graph open?
401+
} else if (graph !== null && msg_in !== '' && ws_msg.packetID) { // is the graph open?
392402
graph_new_data(msg_in);
393403
}
394404
}

Diff for: src/editor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ $(() => {
302302
outTo: 'terminal',
303303
portPath: getComPort(),
304304
baudrate: baudrate.toString(10),
305-
msg: characterToSend,
305+
msg: (clientService.rxBase64 ? btoa(characterToSend) : characterToSend),
306306
action: 'msg'
307307
};
308308
client_ws_connection.send(JSON.stringify(msg_to_send));

0 commit comments

Comments
 (0)