Skip to content

Commit

Permalink
use fwVersion to choose which command use
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomontero committed May 9, 2024
1 parent 685cb56 commit f153515
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
25 changes: 14 additions & 11 deletions src/cmd/serial.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const FlashCommand = require('./flash');
const usbUtils = require('./usb-util');
const { platformForId } = require('../lib/platform');
const { FirmwareModuleDisplayNames } = require('particle-usb');
const semver = require('semver');

const IDENTIFY_COMMAND_TIMEOUT = 20000;

Expand Down Expand Up @@ -266,18 +267,20 @@ module.exports = class SerialCommand extends CLICommandBase {

const features = platformForId(device.platformId).features;
if (features.includes('cellular')) {
let isControlRequestSupported = true;
try {
const cellularMetrics = await device.getCellularInfo();
cellularImei = cellularMetrics.imei;
cellularIccid = cellularMetrics.iccid;
} catch (err) {
// ignore and move on to get other fields
if (err.message === 'Not supported') {
isControlRequestSupported = false;
// since from 6.x onwards we can't use serial to get imei, we use control request
if (semver.gte(fwVer, '6.0.0')) {
try {
const cellularInfo = await device.getCellularInfo({ timeout: 2000 });
if (!cellularInfo) {
throw new VError('No data returned from control request for device info');
}
cellularImei = cellularInfo.imei;
cellularIccid = cellularInfo.iccid;
} catch (err) {
// ignore and move on to get other fields
throw new VError(ensureError(err), 'Could not get device info');
}
}
if (!isControlRequestSupported) {
} else {
try {
const cellularInfo = await this.getDeviceInfoFromSerial(deviceFromSerialPort);
if (!cellularInfo) {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/serial.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Serial Command', () => {
describe('identifyDevice', () => {
it('identifies a cellular device with dvos over serial', async () => {
const deviceId = '1234456789abcdef';
const fwVer = '5.4.0';
const fwVer = '6.1.0';
const imei = '1234';
const iccid = '5678';
const wifiDeviceFromSerialPort = {
Expand Down

0 comments on commit f153515

Please sign in to comment.