Remove Port class

Ultimately unnecessary with Cylon, as opposed to Artoo where we do some
interesting/tricky stuff with Socket-To-Serial to make everything work.
This commit is contained in:
Andrew Stewart 2014-03-18 13:41:12 -07:00
parent 70dde8148c
commit e4c43c0cd5
3 changed files with 5 additions and 185 deletions

View File

@ -9,7 +9,6 @@
'use strict';
require("./robot");
require("./port");
require("./adaptor");
require("./utils");
@ -43,7 +42,7 @@ namespace("Cylon", function() {
this.robot = opts.robot;
this.name = opts.name;
this.connection_id = opts.id;
this.port = new Cylon.Port(opts.port);
this.port = opts.port;
this.adaptor = this.initAdaptor(opts);
proxyFunctionsToObject(this.adaptor.commands(), this.adaptor, this.self);
@ -55,7 +54,7 @@ namespace("Cylon", function() {
Connection.prototype.data = function() {
return {
name: this.name,
port: this.port.toString(),
port: this.port,
adaptor: this.adaptor.constructor.name || this.adaptor.name,
connection_id: this.connection_id
};
@ -70,7 +69,7 @@ namespace("Cylon", function() {
var msg = "Connecting to " + this.name;
if (this.port != null) {
msg += " on port " + this.port.toString();
msg += " on port " + this.port;
}
Logger.info(msg);
@ -84,7 +83,7 @@ namespace("Cylon", function() {
var msg = "Disconnecting from " + this.name;
if (this.port != null) {
msg += " on port " + this.port.toString();
msg += " on port " + this.port;
}
Logger.info(msg);
@ -109,7 +108,7 @@ namespace("Cylon", function() {
var msg = "Halting adaptor " + this.name;
if (this.port != null) {
msg += " on port " + this.port.toString();
msg += " on port " + this.port;
}
Logger.info(msg);

View File

@ -1,75 +0,0 @@
/*
* port
* cylonjs.com
*
* Copyright (c) 2013-2014 The Hybrid Group
* Licensed under the Apache 2.0 license.
*/
'use strict';
var namespace = require('node-namespace');
// The Port class represents a port and/or host to be used to connect to
// a specific hardware device
namespace("Cylon", function() {
return this.Port = (function() {
// Public: Creates a new Port based on a passed String representation
//
// data - string representation of the Port
//
// Returns a new Port
function Port(data) {
this.self = this;
this.isTcp = this.isSerial = this.isPortless = false;
this.parse(data);
}
// Public: Parses the Port's data to determine what kind of port it is
//
// data - string representation of the port to parse
//
// Returns nothing.
Port.prototype.parse = function(data) {
var match;
if (data === void 0) {
this.port = void 0;
return this.isPortless = true;
// is TCP host/port?
} else if (match = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5})/.exec(data)) {
this.port = match[2];
this.host = match[1];
return this.isTcp = true;
// is it a numeric port for localhost tcp?
} else if (/^[0-9]{1,5}$/.exec(data)) {
this.port = data;
this.host = "localhost";
return this.isTcp = true;
// must be a serial port
} else {
this.port = data;
this.host = void 0;
return this.isSerial = true;
}
};
// Public: Returns a string representation of the port that can be used to
// connect to it.
//
// Returns a string
Port.prototype.toString = function() {
if (this.isPortless) {
return "none";
} else if (this.isSerial) {
return this.port;
} else {
return "" + this.host + ":" + this.port;
}
};
return Port;
})();
});
module.exports = Cylon.Port;

View File

@ -1,104 +0,0 @@
'use strict';
source("port");
describe("Port", function() {
describe("remote TCP port", function() {
var port;
port = new Cylon.Port("192.168.0.1:8080");
it("#port", function() {
port.port.should.be.equal("8080");
});
it("#isTcp", function() {
port.isTcp.should.be["true"];
});
it("#isSerial", function() {
port.isSerial.should.be["false"];
});
it("#isPortless", function() {
port.isPortless.should.be["false"];
});
it("#toString", function() {
port.toString().should.be.equal("192.168.0.1:8080");
});
});
describe("local TCP port", function() {
var port;
port = new Cylon.Port("5678");
it("#port", function() {
port.port.should.be.equal("5678");
});
it("#isTcp", function() {
port.isTcp.should.be["true"];
});
it("#isSerial", function() {
port.isSerial.should.be["false"];
});
it("#isPortless", function() {
port.isPortless.should.be["false"];
});
it("#toString", function() {
port.toString().should.be.equal("localhost:5678");
});
});
describe("serial port", function() {
var port;
port = new Cylon.Port("/dev/tty.usb12345");
it("#port", function() {
port.port.should.be.equal("/dev/tty.usb12345");
});
it("#isTcp", function() {
port.isTcp.should.be["false"];
});
it("#isSerial", function() {
port.isSerial.should.be["true"];
});
it("#isPortless", function() {
port.isPortless.should.be["false"];
});
it("#toString", function() {
port.toString().should.be.equal("/dev/tty.usb12345");
});
});
describe("portless", function() {
var port;
port = new Cylon.Port;
it("#port", function() {
assert(port.port === void 0);
});
it("#isTcp", function() {
port.isTcp.should.be["false"];
});
it("#isSerial", function() {
port.isSerial.should.be["false"];
});
it("#isPortless", function() {
port.isPortless.should.be["true"];
});
it("#toString", function() {
port.toString().should.be.equal("none");
});
});
});