1 function NobdyStream(type) {
4 this.propName = type.charAt(0).toLowerCase() + type.slice(1);
6 this[this.propName] = "";
10 NobdyStream.prototype.changed = function (value) { }
11 NobdyStream.prototype.type = undefined;
12 NobdyStream.prototype.propName = "";
13 NobdyStream.prototype.setValue = function(value) {
14 this[this.propName] = value;
18 var nobdy = new Nobdy();
21 this.websocket = undefined;
24 Nobdy.prototype.connect = function(address) {
28 if(typeof MozWebSocket != "undefined")
29 this.websocket = new MozWebSocket("ws://" + address);
30 else this.websocket = new WebSocket("ws://" + address);
32 this.websocket.onopen = function(evt) {
36 this.websocket.onclose = function(evt) {
38 that.setSupported(["Velocity","EngineRPM","EngineCoolantTemp","ThrottlePosition",
39 "IntakeAirTemp","EngineLoad","MassAirFlow"]);
40 that.produceSimulatedData();
43 this.websocket.onmessage = function(evt) {
48 this.websocket.onerror = function(evt) {
52 this.setSupported = function(supportedList) {
53 for(var i=0;i<supportedList.length; i++) {
54 this.supported[supportedList[i]] = supportedList[i];
56 if(!this.isConnected) {
58 this.isConnected = true;
65 Nobdy.prototype.supported = [];
67 Nobdy.prototype.isConnected = false;
69 Nobdy.prototype.simulateData = false;
71 Nobdy.prototype.requestReceived = function(code, value, time) {
72 for(var i=0;i<this.streams.length;i++) {
73 if(this.streams[i].type == code) {
74 this.streams[i].setValue(value);
80 Nobdy.prototype.produceSimulatedData = function () {
82 if(!simulateData) return;
84 if(nobdy.streams.length)
86 for(var i=0;i<nobdy.streams.length;i++) {
89 if(nobdy.streams[i].type == nobdy.supported.Velocity)
91 value = Math.random()*250;
93 else if(nobdy.streams[i].type == nobdy.supported.EngineRPM)
95 value = Math.random()*10000;
97 else if(nobdy.streams[i].type == nobdy.supported.EngineCoolantTemp)
99 value = Math.random()*180;
101 else if(nobdy.streams[i].type == nobdy.supported.ThrottlePosition)
103 value = Math.random()*100;
105 else if(nobdy.streams[i].type == nobdy.supported.IntakeAirTemp)
107 value = Math.random()*200;
109 else if(nobdy.streams[i].type == nobdy.supported.EngineLoad)
111 value = Math.random()*100;
113 else if(nobdy.streams[i].type == nobdy.supported.MassAirFlow)
115 value = Math.random()*2550;
118 nobdy.streams[i].setValue(value);
122 setTimeout(nobdy.produceSimulatedData,1000);
126 Nobdy.prototype.connected = function () { }
128 Nobdy.prototype.createStream = function(code) {
129 this.websocket.send("nobdy.addRequest('"+code+"');");
131 var stream = new NobdyStream(code);
133 this.streams.push(stream);
138 Nobdy.prototype.issueCommand = function(command) {
139 this.websocket.send("nobdy.issueCommand('"+command+"');");