Rename send-kboot-reset.js to send-kboot-command.js and generalize it by allowing various KBOOT commands to be sent.

This commit is contained in:
László Monda
2017-10-23 01:13:36 +02:00
parent 1a0fa5b5ba
commit 1b22a2e739
3 changed files with 40 additions and 7 deletions

View File

@@ -0,0 +1,35 @@
#!/usr/bin/env node
const uhk = require('./uhk');
const path = require('path');
function printUsage() {
const scriptFilename = path.basename(process.argv[1]);
const commands = Object.keys(uhk.kbootCommands).join(' | ');
console.log(
`Usage: ${scriptFilename} command i2cAddress
command: ${commands}
i2cAddress is not needed for the idle command`);
}
const kbootCommand = process.argv[2];
if (!kbootCommand) {
console.log(`No command provided`);
process.exit(1);
}
const kbootCommandId = uhk.kbootCommands[kbootCommand];
if (!kbootCommandId) {
console.log(`Invalid command provided`);
process.exit(1);
}
const i2cAddress = process.argv[3];
if (kbootCommand !== 'idle' && !i2cAddress) {
console.log(`No i2cAddress provided`);
process.exit(1);
}
const device = uhk.getUhkDevice();
let transfer = new Buffer([uhk.usbCommands.sendKbootCommand, kbootCommandId, parseInt(i2cAddress)]);
device.write(uhk.getTransferData(transfer));
const response = Buffer.from(device.readSync());

View File

@@ -1,7 +0,0 @@
#!/usr/bin/env node
const uhk = require('./uhk');
const device = uhk.getUhkDevice();
let transfer = new Buffer([uhk.usbCommands.sendKbootCommand, 0x10]);
device.write(uhk.getTransferData(transfer));
const response = Buffer.from(device.readSync());

View File

@@ -86,6 +86,11 @@ exports = module.exports = moduleExports = {
readUserConfig: 2,
writeUserConfig: 3,
},
kbootCommands: {
idle: 0,
ping: 1,
reset: 2,
},
leftLedDriverAddress: 0b1110100,
rightLedDriverAddress: 0b1110111,
sendLog: sendLog,