Created
September 17, 2015 09:14
-
-
Save Antonasg/5a2ea8f2ccb43e736b29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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