@@ -14,14 +14,10 @@ const { sha512crypt } = require('sha512crypt-node');
14
14
const DownloadManager = require ( '../lib/download-manager' ) ;
15
15
const { platformForId, PLATFORMS } = require ( '../lib/platform' ) ;
16
16
const path = require ( 'path' ) ;
17
- const { getEdlDevices } = require ( 'particle-usb' ) ;
18
- const { delay } = require ( '../lib/utilities' ) ;
19
17
const semver = require ( 'semver' ) ;
20
- const { prepareFlashFiles, getTachyonInfo, promptWifiNetworks } = require ( '../lib/tachyon-utils' ) ;
18
+ const { prepareFlashFiles, getTachyonInfo, promptWifiNetworks, getEDLDevice } = require ( '../lib/tachyon-utils' ) ;
21
19
const { supportedCountries } = require ( '../lib/supported-countries' ) ;
22
20
23
-
24
- const DEVICE_READY_WAIT_TIME = 500 ; // ms
25
21
const showWelcomeMessage = ( ui ) => `
26
22
===================================================================================
27
23
Particle Tachyon Setup Command
@@ -50,7 +46,7 @@ module.exports = class SetupTachyonCommands extends CLICommandBase {
50
46
spinnerMixin ( this ) ;
51
47
this . _setupApi ( ) ;
52
48
this . ui = ui || this . ui ;
53
- this . deviceId = null ;
49
+ this . device = null ;
54
50
this . _baseDir = settings . ensureFolder ( ) ;
55
51
this . _logsDir = path . join ( this . _baseDir , 'logs' ) ;
56
52
@@ -81,12 +77,11 @@ module.exports = class SetupTachyonCommands extends CLICommandBase {
81
77
// step 2 get device info
82
78
this . _formatAndDisplaySteps ( "Now let's get the device info" , 2 ) ;
83
79
this . ui . write ( '' ) ;
84
- const { deviceId, usbVersion } = await this . _verifyDeviceInEDLMode ( ) ;
85
- this . deviceId = deviceId ;
86
- this . usbVersion = usbVersion ;
80
+ const device = await getEDLDevice ( { ui : this . ui , showSetupMessage : true } ) ;
81
+ this . device = device ;
87
82
// ensure logs dir
88
83
await fs . ensureDir ( this . _logsDir ) ;
89
- this . outputLog = path . join ( this . _logsDir , `tachyon_flash_${ this . deviceId } _${ Date . now ( ) } .log` ) ;
84
+ this . outputLog = path . join ( this . _logsDir , `tachyon_flash_${ this . device . id } _${ Date . now ( ) } .log` ) ;
90
85
await fs . ensureFile ( this . outputLog ) ;
91
86
this . ui . write ( `${ os . EOL } Starting Process. See logs at: ${ this . outputLog } ${ os . EOL } ` ) ;
92
87
const deviceInfo = await this . _getDeviceInfo ( ) ;
@@ -111,55 +106,18 @@ module.exports = class SetupTachyonCommands extends CLICommandBase {
111
106
config . packagePath = await this . _downloadStep ( config ) ; // step 6
112
107
this . product = await this . _getProductDetails ( config . productId ) ;
113
108
config . registrationCode = await this . _registerDeviceStep ( config ) ; // step 7
114
- config . esim = await this . _getESIMProfiles ( { deviceId : this . deviceId , country : config . country , productId : config . productId } ) ; // after add device to product
109
+ config . esim = await this . _getESIMProfiles ( { deviceId : this . device . id , country : config . country , productId : config . productId } ) ; // after add device to product
115
110
const { xmlPath } = await this . _configureConfigAndSaveStep ( config ) ; // step 8
116
111
const flashSuccess = await this . _flashStep ( config . packagePath , xmlPath , config ) ; // step 9
117
112
await this . _finalStep ( flashSuccess , config ) ; // step 10
118
113
}
119
114
120
- async _verifyDeviceInEDLMode ( ) {
121
- let edlDevices = [ ] ;
122
- let device ;
123
- let messageShown = false ;
124
- while ( edlDevices . length === 0 ) {
125
- try {
126
- edlDevices = await getEdlDevices ( ) ;
127
- if ( edlDevices . length > 0 ) {
128
- device = edlDevices [ 0 ] ;
129
- break ;
130
- }
131
- if ( ! messageShown ) {
132
- const message = `${ this . ui . chalk . bold ( 'Before we get started, we need to power on your Tachyon board' ) } :` +
133
- `${ os . EOL } ${ os . EOL } ` +
134
- `1. Plug the USB-C cable into your computer and the Tachyon board.${ os . EOL } ` +
135
- ` The red light should turn on!${ os . EOL } ${ os . EOL } ` +
136
- `2. Put the Tachyon device into ${ this . ui . chalk . bold ( 'system update' ) } mode:${ os . EOL } ` +
137
- ` - Hold the button next to the red LED for 3 seconds.${ os . EOL } ` +
138
- ` - When the light starts flashing yellow, release the button.${ os . EOL } ` ;
139
- this . ui . stdout . write ( message ) ;
140
- this . ui . stdout . write ( os . EOL ) ;
141
- messageShown = true ;
142
- }
143
- } catch ( error ) {
144
- // ignore error
145
- }
146
- await delay ( DEVICE_READY_WAIT_TIME ) ;
147
- }
148
- if ( messageShown ) {
149
- this . ui . stdout . write ( `Your device is now in ${ this . ui . chalk . bold ( 'system update' ) } mode!${ os . EOL } ` ) ;
150
- await delay ( 1000 ) ; // give the user a moment to read the message
151
- }
152
- return {
153
- deviceId : device . id ,
154
- usbVersion : device . usbVersion
155
- } ;
156
- }
157
-
158
115
async _getDeviceInfo ( ) {
159
116
try {
160
117
return await this . ui . showBusySpinnerUntilResolved ( 'Getting device info' , getTachyonInfo ( {
161
118
outputLog : this . outputLog ,
162
119
ui : this . ui ,
120
+ device : this . device
163
121
} ) ) ;
164
122
} catch ( error ) {
165
123
// If this fails, the flash won't work so abort early.
@@ -177,10 +135,10 @@ module.exports = class SetupTachyonCommands extends CLICommandBase {
177
135
this . ui . write ( ` - Region: ${ deviceInfo . region } ` ) ;
178
136
this . ui . write ( ` - OS Version: ${ deviceInfo . osVersion } ` ) ;
179
137
let usbWarning = '' ;
180
- if ( this . usbVersion . major <= 2 ) {
138
+ if ( this . device . usbVersion . major <= 2 ) {
181
139
usbWarning = this . ui . chalk . yellow ( ' (use a USB 3.0 port and USB-C cable for faster flashing)' ) ;
182
140
}
183
- this . ui . write ( ` - USB Version: ${ this . usbVersion . major } .${ this . usbVersion . minor } ${ usbWarning } ` ) ;
141
+ this . ui . write ( ` - USB Version: ${ this . device . usbVersion . major } .${ this . device . usbVersion . minor } ${ usbWarning } ` ) ;
184
142
}
185
143
186
144
async _verifyLogin ( ) {
@@ -385,17 +343,18 @@ module.exports = class SetupTachyonCommands extends CLICommandBase {
385
343
const { path : configBlobPath , configBlob } = await this . _runStepWithTiming (
386
344
'Creating the configuration file to write to the Tachyon device...' ,
387
345
9 ,
388
- ( ) => this . _createConfigBlob ( config , this . deviceId )
346
+ ( ) => this . _createConfigBlob ( config , this . device . id )
389
347
) ;
390
348
391
349
const { xmlFile : xmlPath } = await prepareFlashFiles ( {
392
350
logFile : this . outputLog ,
393
351
ui : this . ui ,
394
352
partitionsList : [ 'misc' ] ,
395
353
dir : path . dirname ( configBlobPath ) ,
396
- deviceId : this . deviceId ,
354
+ deviceId : this . device . id ,
397
355
operation : 'program' ,
398
- checkFiles : true
356
+ checkFiles : true ,
357
+ device : this . device
399
358
} ) ;
400
359
// Save the config file if requested
401
360
if ( config . saveConfig ) {
@@ -407,7 +366,7 @@ module.exports = class SetupTachyonCommands extends CLICommandBase {
407
366
408
367
async _flashStep ( packagePath , xmlPath , config ) {
409
368
let message = `Heads up: this is a large image and flashing will take about 2 minutes to complete.${ os . EOL } ` ;
410
- const slowUsb = this . usbVersion . major <= 2 ;
369
+ const slowUsb = this . device . usbVersion . major <= 2 ;
411
370
if ( slowUsb ) {
412
371
message = `Heads up: this is a large image and flashing will take about 8 minutes to complete.${ os . EOL } ` +
413
372
this . ui . chalk . yellow ( `${ os . EOL } The device is connected to a slow USB port. Connect a USB Type-C cable directly to a USB 3.0 port to shorten this step to 2 minutes.${ os . EOL } ` ) ;
@@ -471,7 +430,7 @@ module.exports = class SetupTachyonCommands extends CLICommandBase {
471
430
472
431
_consoleLink ( ) {
473
432
const baseUrl = `https://console${ settings . isStaging ? '.staging' : '' } .particle.io` ;
474
- return `${ baseUrl } /${ this . product . slug } /devices/${ this . deviceId } ` ;
433
+ return `${ baseUrl } /${ this . product . slug } /devices/${ this . device . id } ` ;
475
434
}
476
435
477
436
async _runStepWithTiming ( stepDesc , stepNumber , asyncTask , minDuration = 2000 ) {
@@ -675,8 +634,8 @@ module.exports = class SetupTachyonCommands extends CLICommandBase {
675
634
}
676
635
677
636
async _getRegistrationCode ( productId ) {
678
- await this . _assignDeviceToProduct ( { productId : productId , deviceId : this . deviceId } ) ;
679
- const data = await this . api . getRegistrationCode ( { productId, deviceId : this . deviceId } ) ;
637
+ await this . _assignDeviceToProduct ( { productId : productId , deviceId : this . device . id } ) ;
638
+ const data = await this . api . getRegistrationCode ( { productId, deviceId : this . device . id } ) ;
680
639
return data . registration_code ;
681
640
}
682
641
@@ -733,9 +692,9 @@ module.exports = class SetupTachyonCommands extends CLICommandBase {
733
692
const flashCommand = new FlashCommand ( ) ;
734
693
735
694
if ( ! skipFlashingOs ) {
736
- await flashCommand . flashTachyon ( { files : [ packagePath ] , skipReset : true , output : this . outputLog , verbose : false } ) ;
695
+ await flashCommand . flashTachyon ( { device : this . device , files : [ packagePath ] , skipReset : true , output : this . outputLog , verbose : false } ) ;
737
696
}
738
- await flashCommand . flashTachyonXml ( { files, skipReset, output : this . outputLog } ) ;
697
+ await flashCommand . flashTachyonXml ( { device : this . device , files, skipReset, output : this . outputLog } ) ;
739
698
return true ;
740
699
}
741
700
0 commit comments