blob: 9728946ca519758cbbd1891c3452e0bccc5c5a81 [file] [log] [blame] [raw]
"use strict";
/**
* A modem via UART, like https://github.com/ewiger/jsmodem
* Not particlarly useful for anything, superseded by network.js
*
* @constructor
*/
function ModemAdapter()
{
this.send_char = function() {};
this.enabled = true;
this.socket = new WebSocket("ws://localhost:2080");
this.socket.onopen = this.onopen.bind(this);;
this.socket.onmessage = this.onmessage.bind(this);
this.socket.onclose = this.onclose.bind(this);
this.socket.onerror = this.onerror.bind(this);
this.opened = false;
}
ModemAdapter.prototype.onmessage = function(e)
{
console.log("onmessage", e);
};
ModemAdapter.prototype.onclose = function(e)
{
console.log("onclose", e);
this.opened = false;
};
ModemAdapter.prototype.onopen = function(e)
{
console.log("open", e);
this.opened = true;
};
ModemAdapter.prototype.onerror = function(e)
{
console.log("onerror", e);
};
ModemAdapter.prototype.init = function(code_fn)
{
this.destroy();
this.send_char = code_fn;
};
ModemAdapter.prototype.destroy = function()
{
};
ModemAdapter.prototype.put_str = function(chr)
{
console.log("put_str", chr);
if(this.opened)
{
this.socket.send(chr);
}
}