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

Solo 200 resubmit G - Handle differences in encoding between launcher versions #337

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
32 changes: 21 additions & 11 deletions src/blocklypropclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ var clientService = {
path: 'localhost', // Is this always localhost?
port: 6009, // BlocklyProp Client/Launcher port number
type: null, // {string} Seems to be one of "", "ws", "http"

/*
rxBase64: true,
/*
portListReceiveCountUp: 0, // This is set to 0 each time the port list is received, and incremented once each 4 second heartbeat
activeConnection: null,
*/
Expand Down Expand Up @@ -140,8 +139,8 @@ var find_client = function () {
}
};

var setPropToolbarButtons = function (ui_btn_state) {
if (ui_btn_state === 'available') {
var setPropToolbarButtons = function () {
if (clientService.available) {
if (projectData && projectData.board === 's3') {
// Hide the buttons that are not required for the S3 robot
$('.no-s3').addClass('hidden');
Expand Down Expand Up @@ -209,11 +208,12 @@ var check_client = function () {
if (!data.server || data.server !== 'BlocklyPropHTTP') {
client_version_str = '0.0.0';
}

checkClientVersionModal(client_version_str);

clientService.type = 'http';
clientService.available = true;
setPropToolbarButtons('available');
setPropToolbarButtons();
if (checkForComPorts && typeof (checkForComPorts) === "function") {
checkForComPorts();
check_com_ports_interval = setInterval(checkForComPorts, 5000);
Expand All @@ -226,7 +226,7 @@ var check_client = function () {
clientService.type = 'none';
clientService.available = false;
clientService.portsAvailable = false;
setPropToolbarButtons('unavailable');
setPropToolbarButtons();
check_ws_socket_timeout = setTimeout(find_client, 3000);
});
};
Expand Down Expand Up @@ -342,14 +342,14 @@ function establish_socket() {
if (ws_msg.type === 'hello-client') {
// type: 'hello-client',
// version: [String version (semantic versioning)]
// rxBase64: [boolean, accepts base64-encoded serial streams (all versions transmit base64)]
checkClientVersionModal(ws_msg.version);

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

// TODO: Add version checking here.

clientService.rxBase64 = ws_msg.rxBase64 || false;
clientService.type = 'ws';
clientService.available = true;

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

var msg_in = atob(ws_msg.msg);
var msg_in = '';
try {
var msg_in = atob(ws_msg.msg);
} catch (error) {
// only show the error if it's something other than base-64 encoding
if (error.toString().indexOf("'atob'") < 0) {
console.error(error);
}
msg_in = ws_msg.msg;
}


if (term !== null) { // is the terminal open?
if (term !== null && msg_in !== '' && ws_msg.packetID) { // is the terminal open?
pTerm.display(msg_in);
pTerm.focus();
} else if (graph !== null) { // is the graph open?
} else if (graph !== null && msg_in !== '' && ws_msg.packetID) { // is the graph open?
graph_new_data(msg_in);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ $(() => {
outTo: 'terminal',
portPath: getComPort(),
baudrate: baudrate.toString(10),
msg: characterToSend,
msg: (clientService.rxBase64 ? btoa(characterToSend) : characterToSend),
action: 'msg'
};
client_ws_connection.send(JSON.stringify(msg_to_send));
Expand Down