2012-12-18 15:21:46 +00:00
|
|
|
var readline = require('readline');
|
2013-01-15 22:14:44 +00:00
|
|
|
var dateFormat = require('dateformat');
|
2012-12-17 13:58:03 +00:00
|
|
|
var osc = require('node-osc');
|
|
|
|
|
2013-01-15 21:12:00 +00:00
|
|
|
var listenPort = 8000;
|
|
|
|
var hubAddress = '192.168.23.43';
|
|
|
|
var hubPort = 7110;
|
|
|
|
|
|
|
|
var oscClient = new osc.Client(hubAddress, hubPort);
|
|
|
|
var oscServer = new osc.Server(listenPort, '0.0.0.0');
|
2012-12-18 15:21:46 +00:00
|
|
|
|
2012-12-17 13:58:03 +00:00
|
|
|
oscServer.on("message", function (msg, rinfo) {
|
2013-01-15 22:14:44 +00:00
|
|
|
var dateString = dateFormat(new Date(), "HH:MM:ss.L");
|
|
|
|
console.log(dateString + "\t" + msg);
|
2012-12-17 13:58:03 +00:00
|
|
|
});
|
2012-12-18 15:21:46 +00:00
|
|
|
|
2013-01-15 21:12:00 +00:00
|
|
|
oscClient.send('/subscribe','192.168.23.102', listenPort, "sekret");
|
2012-12-18 15:21:46 +00:00
|
|
|
|
|
|
|
var rl = readline.createInterface(process.stdin,process.stdout,null);
|
|
|
|
|
|
|
|
rl.on('line', function(cmd) {
|
|
|
|
var sepIndex = cmd.indexOf(":");
|
|
|
|
if(sepIndex > 0) {
|
|
|
|
var path = cmd.substr(0, sepIndex);
|
|
|
|
var val = cmd.substr(sepIndex+1);
|
2013-01-15 21:12:00 +00:00
|
|
|
if(isNumber(val)) parseFloat(val);
|
2012-12-18 15:21:46 +00:00
|
|
|
console.log("writing: %s with %s", path, val);
|
|
|
|
oscClient.send(path, val);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
rl.on('close', function(cmd) {
|
|
|
|
console.log("bye bye");
|
2013-01-15 21:12:00 +00:00
|
|
|
oscClient.send('/unsubscribe', hubAddress, listenPort);
|
2012-12-18 15:21:46 +00:00
|
|
|
process.exit(0);
|
|
|
|
});
|
|
|
|
|
2013-01-15 21:12:00 +00:00
|
|
|
|
|
|
|
function isNumber(value) {
|
|
|
|
if ((undefined === value) || (null === value)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (typeof value == 'number') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return !isNaN(value - 0);
|
2013-01-15 22:14:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|