Skip to content

Instantly share code, notes, and snippets.

@sidorares
Created January 20, 2015 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidorares/52b925e3d44a4f4ad06f to your computer and use it in GitHub Desktop.
Save sidorares/52b925e3d44a4f4ad06f to your computer and use it in GitHub Desktop.
module.exports['ch.epfl.mobots.AsebaNetwork'] = function(bus) {
this.addListener = this.on = function(signame, callback) {
bus.addMatch('type=\'signal\',member=\'' + signame + '\'', function(err, result) {
if (err) throw new Error(err);
});
var signalFullName = bus.mangle('/', 'ch.epfl.mobots.AsebaNetwork', signame);
bus.signals.on(signalFullName, function(messageBody) {
callback.apply(null, messageBody);
});
};
this.LoadScripts = function(fileName, callback) {
bus.invoke({
destination: 'ch.epfl.mobots.Aseba',
path: '/',
interface: 'ch.epfl.mobots.AsebaNetwork',
member: 'LoadScripts',
body: [fileName],
signature: 's',
}, callback);
};
this.GetNodesList = function(callback) {
bus.invoke({
destination: 'ch.epfl.mobots.Aseba',
path: '/',
interface: 'ch.epfl.mobots.AsebaNetwork',
member: 'GetNodesList',
}, callback);
};
this.GetNodeId = function(node, callback) {
bus.invoke({
destination: 'ch.epfl.mobots.Aseba',
path: '/',
interface: 'ch.epfl.mobots.AsebaNetwork',
member: 'GetNodeId',
body: [node],
signature: 's',
}, callback);
};
this.GetVariablesList = function(node, callback) {
bus.invoke({
destination: 'ch.epfl.mobots.Aseba',
path: '/',
interface: 'ch.epfl.mobots.AsebaNetwork',
member: 'GetVariablesList',
body: [node],
signature: 's',
}, callback);
};
this.SetVariable = function(node, variable, data, callback) {
bus.invoke({
destination: 'ch.epfl.mobots.Aseba',
path: '/',
interface: 'ch.epfl.mobots.AsebaNetwork',
member: 'SetVariable',
body: [node, variable, data],
signature: 'ssan',
}, callback);
};
this.GetVariable = function(node, variable, callback) {
bus.invoke({
destination: 'ch.epfl.mobots.Aseba',
path: '/',
interface: 'ch.epfl.mobots.AsebaNetwork',
member: 'GetVariable',
body: [node, variable],
signature: 'ss',
}, callback);
};
this.SendEvent = function(event, data, callback) {
bus.invoke({
destination: 'ch.epfl.mobots.Aseba',
path: '/',
interface: 'ch.epfl.mobots.AsebaNetwork',
member: 'SendEvent',
body: [event, data],
signature: 'qan',
}, callback);
};
this.SendEventName = function(name, data, callback) {
bus.invoke({
destination: 'ch.epfl.mobots.Aseba',
path: '/',
interface: 'ch.epfl.mobots.AsebaNetwork',
member: 'SendEventName',
body: [name, data],
signature: 'san',
}, callback);
};
this.CreateEventFilter = function(callback) {
bus.invoke({
destination: 'ch.epfl.mobots.Aseba',
path: '/',
interface: 'ch.epfl.mobots.AsebaNetwork',
member: 'CreateEventFilter',
}, callback);
};
}
module.exports['org.freedesktop.DBus.Properties'] = function(bus) {
this.addListener = this.on = function(signame, callback) {
bus.addMatch('type=\'signal\',member=\'' + signame + '\'', function(err, result) {
if (err) throw new Error(err);
});
var signalFullName = bus.mangle('/', 'org.freedesktop.DBus.Properties', signame);
bus.signals.on(signalFullName, function(messageBody) {
callback.apply(null, messageBody);
});
};
this.Get = function(interface_name, property_name, callback) {
bus.invoke({
destination: 'ch.epfl.mobots.Aseba',
path: '/',
interface: 'org.freedesktop.DBus.Properties',
member: 'Get',
body: [interface_name, property_name],
signature: 'ss',
}, callback);
};
this.Set = function(interface_name, property_name, value, callback) {
bus.invoke({
destination: 'ch.epfl.mobots.Aseba',
path: '/',
interface: 'org.freedesktop.DBus.Properties',
member: 'Set',
body: [interface_name, property_name, value],
signature: 'ssv',
}, callback);
};
this.GetAll = function(interface_name, callback) {
bus.invoke({
destination: 'ch.epfl.mobots.Aseba',
path: '/',
interface: 'org.freedesktop.DBus.Properties',
member: 'GetAll',
body: [interface_name],
signature: 's',
}, callback);
};
}
module.exports['org.freedesktop.DBus.Introspectable'] = function(bus) {
this.addListener = this.on = function(signame, callback) {
bus.addMatch('type=\'signal\',member=\'' + signame + '\'', function(err, result) {
if (err) throw new Error(err);
});
var signalFullName = bus.mangle('/', 'org.freedesktop.DBus.Introspectable', signame);
bus.signals.on(signalFullName, function(messageBody) {
callback.apply(null, messageBody);
});
};
this.Introspect = function(callback) {
bus.invoke({
destination: 'ch.epfl.mobots.Aseba',
path: '/',
interface: 'org.freedesktop.DBus.Introspectable',
member: 'Introspect',
}, callback);
};
}
var dbus = require('dbus-native');
var bus = dbus.sessionBus();
var Aseba = require('./aseba.js')['ch.epfl.mobots.AsebaNetwork'];
var a = new Aseba(bus);
a.SetVariable('thymio-II', 'motor.left.target',[300]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment