Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Source name, master fader and setUniverse #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions ctrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var e131 = require('./main.js');

var Controller = function(ip, universe, channels) {
this.client = e131.createClient(ip, 5568, universe);
var Controller = function(ip, universe, channels, name) {
this.client = e131.createClient(ip, 5568, universe, name);
this.client.UNIVERSE = universe;
this.channels = channels;
this.dmxData = new Array(channels);
Expand All @@ -11,8 +11,17 @@ Controller.prototype.setChannel = function(channel, value) {
this.dmxData[channel - 1] = value;
};

Controller.prototype.send = function() {
this.client.send(this.dmxData);
Controller.prototype.setUniverse = function(universeData) {
this.dmxData = universeData;
};

Controller.prototype.send = function(master) {
var masterised = this.dmxData.map(function(x) {return x * master});
this.client.send(masterised);
};

Controller.prototype.close = function() {
this.client.close();
};

module.exports.Controller = Controller;
Expand Down Expand Up @@ -44,4 +53,4 @@ Pixel.prototype.setAll = function(value) {
}
};

module.exports.Pixel = Pixel;
module.exports.Pixel = Pixel;
97 changes: 16 additions & 81 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
var dgram = require('dgram');
var Buffer = require('buffer').Buffer;

function E131Client(host, port, universe) {
function E131Client(host, port, universe, name) {
var id = this.uuid = 'fc118ca9-9cf0-4861-8ac7-06450a44ba8a';
this.NAME = name || 'sACN source';;
this._host = host;
this._port = port || 5568; //default e1.31 = 5568
this._socket = dgram.createSocket("udp4");
this.sequenceNumber = 0;
this.sequenceNumber = 0;
this.UNIVERSE = universe || 1;

var data = new Array();

data[0] = 0; // RLP preamble size (high)
Expand All @@ -35,88 +35,23 @@ function E131Client(host, port, universe) {
data[21] = 4;

var cid;

for (var i = 0, j = 22; i < 32; i += 2) {
cid = id.charAt(i) + id.charAt(i + 1);

data[j++] = parseInt(cid, 16);
}

data[38] = 114; // Framing Protocol flags and length (high)
data[39] = 88; // 637 - 38
data[40] = 0; // Framing Vector (indicates that the E1.31 framing layer is wrapping a DMP PDU)
data[41] = 0;
data[42] = 0;
data[43] = 2;
data[44] = 0; // Source Name (64 bytes)
data[45] = 0;
data[46] = 0;
data[47] = 0;
data[48] = 0;
data[49] = 0;
data[50] = 0;
data[51] = 0;
data[52] = 0;
data[53] = 0;
data[54] = 0;
data[55] = 0;
data[56] = 0;
data[57] = 0;
data[58] = 0;
data[59] = 0;
data[60] = 0;
data[61] = 0;
data[61] = 0;
data[62] = 0;
data[63] = 0;
data[64] = 0;
data[65] = 0;
data[66] = 0;
data[67] = 0;
data[68] = 0;
data[69] = 0;
data[70] = 0;
data[71] = 0;
data[71] = 0;
data[72] = 0;
data[73] = 0;
data[74] = 0;
data[75] = 0;
data[76] = 0;
data[77] = 0;
data[78] = 0;
data[79] = 0;
data[80] = 0;
data[81] = 0;
data[81] = 0;
data[82] = 0;
data[83] = 0;
data[84] = 0;
data[85] = 0;
data[86] = 0;
data[87] = 0;
data[88] = 0;
data[89] = 0;
data[90] = 0;
data[91] = 0;
data[91] = 0;
data[92] = 0;
data[93] = 0;
data[94] = 0;
data[95] = 0;
data[96] = 0;
data[97] = 0;
data[98] = 0;
data[99] = 0;
data[100] = 0;
data[101] = 0;
data[101] = 0;
data[102] = 0;
data[103] = 0;
data[104] = 0;
data[105] = 0;
data[106] = 0;
data[107] = 0;

var namechar;
for (var i = 0, j = 44; i < 16; i++) {
namechar = this.NAME.charCodeAt(i);
data[j++] = namechar;
}
data[108] = 100; // Priority
data[109] = 0; // Reserved
data[110] = 0; // Reserved
Expand Down Expand Up @@ -145,8 +80,8 @@ function isNumber(n) {

exports.E131Client = E131Client;

exports.createClient = function(host, port, universe) {
return new E131Client(host, port, universe);
exports.createClient = function(host, port, universe, name) {
return new E131Client(host, port, universe, name);
}

E131Client.prototype.send = function(data) {
Expand All @@ -156,9 +91,9 @@ E131Client.prototype.send = function(data) {
var buf = Buffer(data, 'hex');
var i = numChannels + 1;
var hi;

buf[111] = this.sequenceNumber < 255 ? ++this.sequenceNumber : this.sequenceNumber = 0;

buf[111] = this.sequenceNumber < 255 ? ++this.sequenceNumber : this.sequenceNumber = 0;
buf[123] = i >> 8;
buf[124] = i;

Expand All @@ -179,11 +114,11 @@ E131Client.prototype.send = function(data) {
hi = i >> 8;
buf[115] = hi + 0x70;
buf[116] = i;

this._socket.send(buf, 0, buf.length, this._port, this._host, function() {});

}

E131Client.prototype.close = function() {
this._socket.close();
};
};