Skip to content

Commit

Permalink
Merge pull request #661 from particle-iot/feature/local-flash
Browse files Browse the repository at this point in the history
Local flash
  • Loading branch information
monkbroc authored Aug 21, 2023
2 parents 86a59f6 + 863120e commit c6854b2
Show file tree
Hide file tree
Showing 26 changed files with 2,064 additions and 173 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ executors:

orbs:
node: circleci/[email protected]
win: circleci/windows@4.1.1
win: circleci/windows@5.0.0

commands:
configure-npm-token:
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
- run:
name: Install Node
command: |
nvm install --lts << parameters.node-version >>
nvm install << parameters.node-version >>
nvm use << parameters.node-version >>
- configure-npm-token
- run:
Expand Down
Binary file added assets/knownApps/p2/tinker-5.0.0-p2.bin
Binary file not shown.
152 changes: 126 additions & 26 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@
}
],
"dependencies": {
"@particle/device-constants": "^3.1.9",
"@particle/device-constants": "^3.1.11",
"binary-version-reader": "^2.2.0",
"chalk": "^2.4.2",
"cli-progress": "^3.12.0",
"cli-spinner": "^0.2.10",
"cli-table": "^0.3.1",
"core-js": "^3.4.7",
Expand Down Expand Up @@ -101,7 +102,7 @@
"sinon-chai": "^3.3.0"
},
"optionalDependencies": {
"particle-usb": "^2.2.2",
"particle-usb": "^2.3.1",
"serialport": "^9.2.8"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion src/app/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module.exports = class CLI {
* @param {*} argv The parsed command line arguments.
*/
parsed(argv) {
global.isInteractive = argv.interactive === true || (process.stdin.isTTY && !argv.nonInteractive);
global.isInteractive = process.stdin.isTTY && process.stdout.isTTY;
global.verboseLevel = argv.verbose+1-argv.quiet;
global.outputJson = argv.json;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const log = require('../lib/log');

Spinner.setDefaultSpinnerString(Spinner.spinners[7]);


// TODO: migrate all usage prompt in src/app/ui to src/lib/ui
module.exports.prompt = async (question) => {
if (!global.isInteractive){
throw new Error('Prompts are not allowed in non-interactive mode');
Expand Down
25 changes: 22 additions & 3 deletions src/cli/flash.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const unindent = require('../lib/unindent');

module.exports = ({ commandProcessor, root }) => {
commandProcessor.createCommand(root, 'flash', 'Send firmware to your device', {
params: '[device|binary] [files...]',
Expand All @@ -6,6 +8,10 @@ module.exports = ({ commandProcessor, root }) => {
boolean: true,
description: 'Flash over the air to the device. Default if no other flag provided'
},
'local': {
boolean: true,
description: 'Flash locally, updating Device OS as needed'
},
'usb': {
boolean: true,
description: 'Flash over USB using the DFU utility'
Expand All @@ -27,7 +33,11 @@ module.exports = ({ commandProcessor, root }) => {
description: 'Answer yes to all questions'
},
'target': {
description: 'The firmware version to compile against. Defaults to latest version, or version on device for cellular.'
description: 'The firmware version to compile against. Defaults to latest version.'
},
'application-only': {
boolean: true,
description: 'Do not update Device OS'
},
'port': {
describe: 'Use this serial port instead of auto-detecting. Useful if there are more than 1 connected device. Only available for serial'
Expand All @@ -40,10 +50,19 @@ module.exports = ({ commandProcessor, root }) => {
examples: {
'$0 $command red': 'Compile the source code in the current directory in the cloud and flash to device red',
'$0 $command green tinker': 'Flash the default Tinker app to device green',
'$0 $command blue app.ino --target 0.6.3': 'Compile app.ino in the cloud using the 0.6.3 firmware and flash to device blue',
'$0 $command blue app.ino --target 5.0.0': 'Compile app.ino in the cloud using the 5.0.0 firmware and flash to device blue',
'$0 $command cyan firmware.bin': 'Flash the pre-compiled binary to device cyan',
'$0 $command --local': 'Compile the source code in the current directory in the cloud and flash to the device connected over USB',
'$0 $command --local --target 5.0.0': 'Compile the source code in the current directory in the cloud against the target version and flash to the device connected over USB',
'$0 $command --local application.bin': 'Flash the pre-compiled binary to the device connected over USB',
'$0 $command --local application.zip': 'Flash the pre-compiled binary and assets from the bundle to the device connected over USB',
'$0 $command --local tinker': 'Flash the default Tinker app to the device connected over USB',
'$0 $command --usb firmware.bin': 'Flash the binary over USB. The device needs to be in DFU mode',
'$0 $command --serial firmware.bin': 'Flash the binary over virtual serial port. The device needs to be in listening mode'
}
},
epilogue: unindent(`
When passing the --local flag, Device OS will be updated if the version on the device is outdated.
When passing both the --local and --target flash, Device OS will be updated to the target version.
`)
});
};
9 changes: 9 additions & 0 deletions src/cmd/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ module.exports = class ParticleApi {
);
}

getDeviceOsVersions(platformId, version) {
return this._wrap(
this.api.get({
uri: `/v1/device-os/versions/${version}?platform_id=${platformId}`,
auth: this.accessToken
})
);
}

_wrap(promise){
return Promise.resolve(promise)
.then(result => result.body || result)
Expand Down
20 changes: 19 additions & 1 deletion src/cmd/bundle.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const fs = require('fs-extra');
const path = require('path');
const CLICommandBase = require('./base');
const { createApplicationAndAssetBundle } = require('binary-version-reader');
const { createApplicationAndAssetBundle, unpackApplicationAndAssetBundle, createAssetModule } = require('binary-version-reader');
const utilities = require('../lib/utilities');
const os = require('os');
const temp = require('temp').track();

const specialFiles = [
'.DS_Store',
Expand Down Expand Up @@ -121,4 +122,21 @@ module.exports = class BundleCommands extends CLICommandBase {
this.ui.stdout.write(`Bundling successful.${os.EOL}`);
this.ui.stdout.write(`Saved bundle to: ${bundleFilename}${os.EOL}`);
}

async extractModulesFromBundle({ bundleFilename }) {
const modulesDir = await temp.mkdir('modules');

const { application, assets } = await unpackApplicationAndAssetBundle(bundleFilename);

// Write the app binary and asset modules to disk
application.path = path.join(modulesDir, application.name);
await fs.writeFile(application.path, application.data);
for (const asset of assets) {
const assetModule = await createAssetModule(asset.data, asset.name);
asset.path = path.join(modulesDir, asset.name);
await fs.writeFile(asset.path, assetModule);
}

return [application.path, ...assets.map(asset => asset.path)];
}
};
Loading

0 comments on commit c6854b2

Please sign in to comment.