Skip to content

Instantly share code, notes, and snippets.

@Antonasg
Created September 17, 2015 09:14
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 Antonasg/5a2ea8f2ccb43e736b29 to your computer and use it in GitHub Desktop.
Save Antonasg/5a2ea8f2ccb43e736b29 to your computer and use it in GitHub Desktop.
function transmitCommand(identifier,command) {
console.log('In transmit command');
console.log('identifier: ' + numHex(identifier));
console.log('command: ' + command);
var txAddress = parseInt("0xE8E8F0"+numHex(identifier)+"E2", 16);
tx = radio.openPipe('tx', txAddress,{autoAck:true});
tx.on('ready', function () {
console.log("Radio is ready:");
//radio.printDetails();
console.log("Transmitting command:" + command + "for identifier"+ identifier);
var b = new Buffer([command, identifier]);
try {
var err = tx.write(b);
throw err;
} catch (err) {
console.log(err);
} finally {
//rx.close();
//tx.close();
}
//no error:
// if turn on command, add to turnedOnNodes
if (command == Command.TurnOn) {
addNode(numHex(identifier),true);
} else if (command == Command.TurnOff) {
addNode(numHex(identifier),false);
}
});
tx.on('error', function (error) {
console.log("an error has happened trying to transmit to node."+error);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment