Make the firmware updater scripts take module slot parameters instead of I2C addresses. Rename scripts from *slave* to *module*.

This commit is contained in:
László Monda
2017-11-08 18:27:45 +01:00
parent 9a5862b57c
commit 04b43896c5
8 changed files with 98 additions and 65 deletions

View File

@@ -0,0 +1,38 @@
#!/usr/bin/env node
const uhk = require('./uhk');
const program = require('commander');
const path = require('path');
program
.usage(`command [moduleSlot]
command: ${Object.keys(uhk.kbootCommands).join(' | ')}
moduleSlot: ${Object.keys(uhk.moduleSlotToI2cAddress).join(' | ')}
moduleSlot is always required, except for the idle command.`)
.parse(process.argv)
const kbootCommand = program.args[0];
if (!kbootCommand) {
console.log(`No command provided.`);
console.log(`Valid commands: ${Object.keys(uhk.kbootCommands).join(', ')}`);
process.exit(1);
}
const kbootCommandId = uhk.kbootCommands[kbootCommand];
if (kbootCommandId === undefined) {
console.log(`Invalid command "${kbootCommand}" provided.`);
console.log(`Valid commands: ${Object.keys(uhk.kbootCommands).join(', ')}`);
process.exit(1);
}
const moduleSlot = program.args[1];
let i2cAddress;
if (kbootCommand !== 'idle') {
i2cAddress = uhk.checkModuleSlot(moduleSlot, uhk.moduleSlotToI2cAddress);
}
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());