Commit 26d94159 authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

is streaming on node server

parent 26d81ff8
<div id="positionData">
</div><br/>
<a href="#" id="askForPosition" class="btn btn-block btn-lg btn-default">Refresh</a>
<a href="#" id="askForPosition" class="btn btn-block btn-lg btn-warning">Pause</a>
<a href="#" id="pauseOutput" class="btn btn-block btn-lg btn-warning">Pause</a>
<a href="#" id="stopMachine" class="btn pull-right btn-block btn-lg btn-danger">Stop</a>
\ No newline at end of file
......@@ -11,7 +11,9 @@ define(['jquery', 'underscore', 'backbone', 'text!PositionControlPanelView.html'
el: "#positionPanel",
events: {
"click #stopMachine": "_stopMachine",
"click #pauseOutput": "_pause",
"click #askForPosition": "_askForPosition"
},
......@@ -21,7 +23,6 @@ define(['jquery', 'underscore', 'backbone', 'text!PositionControlPanelView.html'
_renderPositionData: function(){
var machineState = this.model.getMachineState();
console.log(machineState);
if (machineState === null) {
$("#positionData").html("<div id='positionDataError'>no position data available</div>");
return;
......@@ -38,7 +39,7 @@ define(['jquery', 'underscore', 'backbone', 'text!PositionControlPanelView.html'
this._renderPositionData();
},
template: _.template(template),
template: _.template(template)
});
......
......@@ -3,27 +3,24 @@
*/
define(['jquery', 'underscore', 'commParentMenu', 'serialComm', 'text!SerialMonitorView.html'],
function($, _, CommParentMenu, serialComm, template){
define(['jquery', 'underscore', 'backbone', 'serialComm', 'text!SerialMonitorView.html'],
function($, _, Backbone, serialComm, template){
return CommParentMenu.extend({
return Backbone.View.extend({
el: "#serialMonitorView",
parentEvents: {
},
events: {
"click #clearMonitor": "_clear",
"change input:checkbox": "_clickCheckbox"
},
__initialize: function(){
initialize: function(){
_.bindAll(this, "_onKeyUp");
$(document).bind('keyup', {}, this._onKeyUp);
this.listenTo(serialComm, "change:lastMessageReceived", this._updateIncomingMessage);
this.listenTo(serialComm, "change:lastMessageSent", this._updateOutgoingMessage);
this.listenTo(serialComm, "change:baudRate change:portName", this.render);
this.listenTo(serialComm, "change:connected", function(){
......@@ -79,6 +76,14 @@ define(['jquery', 'underscore', 'commParentMenu', 'serialComm', 'text!SerialMoni
}
},
_sendMessage: function(e){
e.preventDefault();
var message = $("#sendSerialMessage").val();
$("#sendSerialMessage").val("");
if (message == "") return;
serialComm.send(message);
},
_makeTemplateJSON: function(){
return this.model.toJSON();
},
......@@ -101,14 +106,18 @@ define(['jquery', 'underscore', 'commParentMenu', 'serialComm', 'text!SerialMoni
_clear: function(e){
e.preventDefault();
this.render();
$("#serialMonitorOutput").html("");
},
_close: function(){
this.userInitedReload = false;
window.close();
},
render: function(){
if ($("input[type=text]").is(":focus")) return;
this.$el.html(this.template(this._makeTemplateJSON()));
},
template: _.template(template)
});
......
......@@ -299,7 +299,6 @@ define(['underscore', 'three', 'backbone', 'appState', 'latticeCAM', 'threeModel
scaledSettings, function(){
currentLine++;
self.set("simLineNumber", currentLine);
console.log(self);
self._stockSimulation();
});
} else {
......
......@@ -18,32 +18,28 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s
},
__initialize: function(){
this.isStreaming = false;
_initialize: function(){
this.listenTo(this.model, "change:stockSimulationPlaying", this.render);
this.listenTo(serialComm, "change:isStreaming", this.render);
this.listenTo(cam, "change:simLineNumber", this._drawGcodeHighlighter);
},
_startStream: function(e){
e.preventDefault();
this.model.set("stockSimulationPlaying", true);
this.isStreaming = true;
this.render();
serialComm.startStream();
},
_pauseStream: function(e){
e.preventDefault();
this.model.set("stockSimulationPlaying", false);
this.isStreaming = false;
this.render();
serialComm.pauseStream();
},
_stopMachine: function(e){
e.preventDefault();
this.model.set("stockSimulationPlaying", false);
this.isStreaming = false;
serialComm.send("!");
this.render();
serialComm.stopStream();
},
_decrementLineNum: function(e){
......@@ -63,7 +59,6 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s
_drawGcodeHighlighter: function(){
var lineNum = cam.get("simLineNumber");
console.log(lineNum);
if (lineNum == 0) return;
var code = cam.get("dataOut").split("\n");
code[lineNum] = "<span id='gcodeHighlighter'>" + code[lineNum] + " </span>";
......@@ -78,7 +73,7 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s
},
_makeTemplateJSON: function(){
return _.extend(serialComm.toJSON(), commPlist, cam.toJSON(), camPlist, {streaming: this.isStreaming});
return _.extend(serialComm.toJSON(), commPlist, cam.toJSON(), camPlist);
},
_render: function(){
......
......@@ -2,7 +2,7 @@
<% if(dataOut==0){ %>
You need to go through the Assemble workflow to setup your machine and create <%= allCamProcesses[camProcess] %> first.
<% }else{ %>
<% if(streaming){ %>
<% if(isStreaming){ %>
<a href="#" id="pauseStream" class="btn btn-halfWidth btn-lg btn-warning">Pause</a>
<a href="#" id="stopMachine" class="btn pull-right btn-halfWidth btn-lg btn-danger">Stop</a><br/>
<% }else{ %>
......
......@@ -14,7 +14,8 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backb
baudRate: 200,
error: null,
lastMessageReceived: null,
lastMessageSent: ""
lastMessageSent: "",
isStreaming: false
},
initialize: function(){
......@@ -47,6 +48,18 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backb
this.socket.emit("flush");
},
startStream: function(){
this.socket.emit("startStream");
},
pauseStream: function(){
this.socket.emit("pauseStream");
},
stopStream: function(){
this.socket.emit("stopStream");
},
refreshMachineState: function(){//when updating connection, create a new instance of machine state
if (this.machineState) this.machineState.destroy();
this.machineState = new MachineState();
......@@ -97,6 +110,11 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backb
serialComm.trigger("change:lastMessageSent");
});
socket.on('isStreaming', function(data){
console.log(data);
serialComm.set("isStreaming", data);
});
socket.on('portConnected', function(data){
console.log("connected port " + data.portName + " at " + data.baudRate);
serialComm.set("baudRate", data.baudRate);
......
......@@ -19,6 +19,7 @@ var io = require('socket.io').listen(8080);
var portName = null;
var currentPort = null;
var baudRate = 115200;
var isStreaming = false;
//io.sockets.on('connection', function (socket) {
// io.emit('baudRate', baudRate);
......@@ -50,6 +51,10 @@ io.on('connection', function(socket){
});
socket.on('dataOut', function(data){
outputData(data);
});
function outputData(data){
io.emit('dataSent', data);
data += '\n';
console.log("Sending data: " + data);
......@@ -57,7 +62,7 @@ io.on('connection', function(socket){
if (err) onPortError(err);
});
// currentPort.write(new Buffer([parseInt(data)]));//write byte
});
}
socket.on('flush', function(){
if (currentPort) currentPort.flush(function(){
......@@ -70,6 +75,25 @@ io.on('connection', function(socket){
allPorts = refreshAvailablePorts();
});
socket.on('stopStream', function(){
outputData("!");
setIsStreaming(false);
});
socket.on('startStream', function(){
setIsStreaming(true);
});
socket.on('pauseStream', function(){
setIsStreaming(false);
});
function setIsStreaming(state){
if (state == isStreaming) return;
isStreaming = state;
io.emit('isStreaming', isStreaming);
}
function checkThatPortExists(_portName){
if (allPorts.indexOf(_portName) < 0) {
onPortError("no available port called " + _portName);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment