-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcan-flash-serial.ts
More file actions
67 lines (59 loc) · 2.99 KB
/
can-flash-serial.ts
File metadata and controls
67 lines (59 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { SerialConnector } from "./serial-connector";
// eslint-disable-next-line @typescript-eslint/no-var-requires
// const drivelist = require('drivelist');
import fs from 'fs';
import inquirer from 'inquirer';
import util from 'util';
import Path from 'path';
const SERIAL_PREFIX = '\x1b[33m[SER]\x1b[0m';
export async function canFlashSerial(deviceId: string) {
let device = (await SerialConnector.list()).find(d => d.path === deviceId);
if (!device) {
console.error(SERIAL_PREFIX, 'Cannot find ' + deviceId + ' in list anymore');
return false;
}
if (device.vendorId === '0483' && device.productId?.toUpperCase() === '374B') {
// DISCO-L475VG
console.log(SERIAL_PREFIX, 'Detected ST B-L475E-IOT01A board, but failed to read config.');
console.log(SERIAL_PREFIX, 'This can be because the device is not running the right firmware ' +
'or because the device is not responsive (f.e. still scanning for WiFi networks).');
console.log(SERIAL_PREFIX);
console.log(SERIAL_PREFIX, 'To flash the Edge Impulse firmware:');
console.log(SERIAL_PREFIX, '1. Download the latest version of the firmware from ' +
'https://cdn.edgeimpulse.com/firmware/DISCO-L475VG-IOT01A.bin');
console.log(SERIAL_PREFIX, '2. Copy the "DISCO-L475VG-IOT01A.bin" file to the DIS_L4IOT drive ' +
'(mounted as USB mass-storage device).');
console.log(SERIAL_PREFIX, '3. Wait until the red/yellow LEDs stopped flashing.');
console.log(SERIAL_PREFIX, '4. Restart this application.');
console.log('');
// eslint-disable-next-line max-len
// let drives: { description: string, mountpoints: { label: string, path: string }[] }[] = await drivelist.list();
// let d = drives.find(l => l.mountpoints.some(m => m.label === 'DIS_L4IOT'));
// if (!d) {
// d = drives.find(l => l.description === 'MBED microcontroller USB Device');
// }
// if (!d) {
// console.error(SERIAL_PREFIX, 'Detected ST B-L475E-IOT01A board but cannot find ' +
// 'mount point');
// return false;
// }
// let flashRes = await inquirer.prompt([{
// type: 'confirm',
// name: 'flash',
// message: 'ST B-L475E-IOT01A board detected, but cannot read config. ' +
// 'Do you want to flash the Edge Impulse firmware for this board?',
// pageSize: 20
// }]);
// if (!flashRes.flash) return false;
// let source = Path.join(__dirname, '..', '..', 'firmware', 'DISCO-L475VG-IOT01A.bin');
// console.log(SERIAL_PREFIX, 'Copying from', source, 'to', d.mountpoints[0].path);
// await util.promisify(fs.copyFile)(
// source,
// Path.join(d.mountpoints[0].path, Path.basename(source)));
// console.log(SERIAL_PREFIX, 'Copied from', source, 'to', d.mountpoints[0].path);
return false;
}
else {
return false;
}
}