From 4845e90e5ca87b1483536d48575fe7f98c62cb95 Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Sat, 30 Jun 2018 17:17:54 +0200 Subject: [PATCH] Update sumorobot.js --- assets/js/sumorobot.js | 48 ++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/assets/js/sumorobot.js b/assets/js/sumorobot.js index 560a208..8c40bf8 100755 --- a/assets/js/sumorobot.js +++ b/assets/js/sumorobot.js @@ -4,13 +4,15 @@ var hotkeys = true; var remoteControl = false; /* the local/remote server URL */ //var robotServer = "10.42.0.1"; -var robotServer = "iot.koodur.com"; +var robotServer = "achex.ca:4010"; /* ace editor object */ var codingEditor = null; /* read only ace editor object */ var readOnlyCodingEditor = null; +// sumorobot ID +var robotId = ""; /* the sumorobot code */ var sumocode = ""; /* the sumorobot object */ @@ -516,18 +518,18 @@ window.onload = function() { /* if we are in coding mode */ if (codingEnabled) { /* send the code from the textarea to the SumoRobot */ - sumorobot.send("start:" + codingEditor.getValue()); + sumorobot.send("{'to':'sumo-" + robotId + "@00000514','cmd': 'code', 'val': '" + codingEditor.getValue() + "'}); /* otherwise when we are in Blockly mode */ } else { /* send the code from the blocks to the SumoRobot */ - sumorobot.send("start:" + sumocode); + sumorobot.send("{'to':'sumo-" + robotId + "@00000514','cmd': 'code', 'val': '" + sumocode + "'}); } }); /* stop button listener */ $(".btn-stop").click(function() { sumostart = false; - sumorobot.send("stop"); + sumorobot.send("{'to':'sumo-" + robotId + "@00000514','cmd': 'stop'}"); workspace.highlightBlock(lastHighlighted, false); }); @@ -538,31 +540,12 @@ window.onload = function() { $(".btn-robot-go").click(); } }); - - /* when robot-id input field gets focused */ - $("#robot-id").focus(function() { - /* if there is no value in the robot-id input field */ - if (!$("#robot-id").val()) { - /* add "sumo-" to the input field so the user */ - /* just has to add the robot ID */ - $("#robot-id").val("sumo-"); - } - }); - - /* when robot-id input field gets unfocused */ - $("#robot-id").blur(function() { - /* if the robot-id input value is the previously set "sumo-" */ - if ($("#robot-id").val() === "sumo-") { - /* remove the value */ - $("#robot-id").val(""); - } - }); /* robot number button listener */ $(".btn-robot-go").click(function() { /* extract and validate the selected robot ID */ - var robotId = $("#robot-id").val().trim(); - if (robotId === "" || /^(sumo-[a-f0-9]{6})$/.test(robotId) == false) { + robotId = $("#robot-id").val().trim(); + if (robotId === "" || /^([a-f0-9]{6})$/.test(robotId) == false) { $("#robot-id, #robot-label").addClass("has-error"); return; } else { @@ -571,23 +554,24 @@ window.onload = function() { /* update robot IDs in local storage */ setLocalStorageItem("sumorobot.robotId", robotId); /* in case there is a open connection */ - if (sumorobot && blockHighlight) { + if (sumorobot/* && blockHighlight*/) { /* close the connections */ sumorobot.close(); - blockHighlight.close(); + //blockHighlight.close(); } /* connect to the selected robots WebSocket */ - sumorobot = new Sumorobot("ws://" + robotServer + ":80/p2p/browser/" + robotId + "/"); + sumorobot = new Sumorobot("ws://" + robotServer); + sumorobot.send("{'setID': 'browser-" + robotId + "@00000514', 'passwd': 'salakala'}"); /* connect to the other block highlight WebSocket */ - blockHighlight = new WebSocket("ws://" + robotServer + ":80/p2p/browser/" + robotId + "-highlight/"); - /* when there is a message from the WebSocket */ + /*blockHighlight = new WebSocket("ws://" + robotServer + ":80/p2p/browser/" + robotId + "-highlight/"); + // when there is a message from the WebSocket blockHighlight.onmessage = function(evt) { - /* when scope is received */ + // when scope is received if (evt.data.length == 20 && sumostart) { workspace.highlightBlock(evt.data); lastHighlighted = evt.data; } - }; + };*/ /* hide the configuration panel */ $("#panel").hide(); });