feat(device): flash device firmware from Agent (#499)
* add dataModelVersion, usbProtocolVersion, slaveProtocolVersion * read the package.json at appstart * flash firmware * update firmware * fix extra resource path * fix import modules * update lock files * fix imports * terminal window * exclude tmp folder from git repo * ok button * auto scroll in xterm * fix maxTry count calculation * optimize logging * optimize timeout * readSync * Add extra delay * fix async call * fix error message in log * fix ok button disable state * retry * list devices * close device after reenumeration * retry snooze * kboot maxtry 10 * retry 100 * remove deprecated toPayload ngrx helper * flash firmware with custom file * fix tslint
This commit is contained in:
committed by
László Monda
parent
f608791a09
commit
297fd3be79
@@ -0,0 +1,48 @@
|
||||
const request = require('request');
|
||||
const decompress = require('decompress');
|
||||
const decompressTarbz = require('decompress-tarbz2');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const fse = require('fs-extra');
|
||||
|
||||
async function downloadFirmware(version) {
|
||||
const url = `https://github.com/UltimateHackingKeyboard/firmware/releases/download/${version}/uhk-firmware-${version}.tar.bz2`;
|
||||
const outputDir = path.join(__dirname, `../tmp`);
|
||||
const output = path.join(outputDir, `uhk-firmware-${version}.tar.bz2`);
|
||||
|
||||
if (!fs.existsSync(outputDir))
|
||||
fs.mkdirSync(outputDir);
|
||||
|
||||
await downloadFile(url, output);
|
||||
|
||||
return Promise.resolve(output);
|
||||
}
|
||||
|
||||
async function downloadFile(url, output) {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log(`Start download ${url}`);
|
||||
|
||||
const r = request(url);
|
||||
r.on('end', () => {
|
||||
resolve(output);
|
||||
});
|
||||
r.on('error', (error) => {
|
||||
reject(error);
|
||||
});
|
||||
|
||||
r.pipe(fs.createWriteStream(output));
|
||||
})
|
||||
}
|
||||
|
||||
(async function main() {
|
||||
const agentJson = require('../packages/uhk-agent/src/package.json');
|
||||
|
||||
const extractedFirmwareDir = path.join(__dirname, '../tmp/packages/firmware');
|
||||
await fse.emptyDir(extractedFirmwareDir);
|
||||
|
||||
// Download the firmware and add as extra resources
|
||||
const firmwarePath = await downloadFirmware(agentJson.firmwareVersion);
|
||||
await decompress(firmwarePath, extractedFirmwareDir, {plugins: [decompressTarbz()]});
|
||||
|
||||
await fse.remove(firmwarePath);
|
||||
})();
|
||||
Reference in New Issue
Block a user