chore(kboot): add more logging (#1004)

This commit is contained in:
Róbert Kiss
2019-07-30 22:23:38 +02:00
committed by László Monda
parent db2e14a852
commit 4d2d6d40fb
2 changed files with 24 additions and 1 deletions

View File

@@ -33,13 +33,14 @@ export class UsbPeripheral implements Peripheral {
logger('Available devices');
const device = devices()
.map(x => {
logger('%O', x);
logger('%o', x);
return x;
})
.find(deviceFinder(this.options));
if (!device) {
logger('USB device can not be found %o', this.options);
throw new Error('USB device can not be found');
}
@@ -80,10 +81,12 @@ export class UsbPeripheral implements Peripheral {
const firsCommandResponse = await this.sendCommand(command);
if (firsCommandResponse.tag !== ResponseTags.Generic) {
logger('Invalid write memory response! %o', firsCommandResponse);
return reject(new Error('Invalid write memory response!'));
}
if (firsCommandResponse.code !== 0) {
logger('Non zero write memory response! %o', firsCommandResponse);
return reject(new Error(`Non zero write memory response! Response code: ${firsCommandResponse.code}`));
}
@@ -110,10 +113,12 @@ export class UsbPeripheral implements Peripheral {
const secondCommandResponse = await this._getNextCommandResponse();
if (secondCommandResponse.tag !== ResponseTags.Generic) {
logger('Invalid write memory final response %o', secondCommandResponse);
return reject(new Error('Invalid write memory final response!'));
}
if (secondCommandResponse.code !== 0) {
logger('Non zero write memory final response %o', secondCommandResponse);
const msg = `Non zero write memory final response! Response code: ${secondCommandResponse.code}`;
return reject(new Error(msg));
}
@@ -142,10 +147,12 @@ export class UsbPeripheral implements Peripheral {
this._resetResponseBuffer();
const firsCommandResponse = await this.sendCommand(command);
if (firsCommandResponse.tag !== ResponseTags.ReadMemory) {
logger('Invalid read memory response %o', firsCommandResponse);
return reject(new Error('Invalid read memory response!'));
}
if (firsCommandResponse.code !== 0) {
logger('Non zero read memory response %o', firsCommandResponse);
return reject(new Error(`Non zero read memory response! Response code: ${firsCommandResponse.code}`));
}
@@ -155,10 +162,12 @@ export class UsbPeripheral implements Peripheral {
const secondCommandResponse = await this._getNextCommandResponse();
if (secondCommandResponse.tag !== ResponseTags.Generic) {
logger('Invalid read memory final response %o', secondCommandResponse);
return reject(new Error('Invalid read memory final response!'));
}
if (secondCommandResponse.code !== 0) {
logger('Non zero read memory final response %o', secondCommandResponse);
const msg = `Non zero read memory final response! Response code: ${secondCommandResponse.code}`;
return reject(new Error(msg));
}
@@ -243,6 +252,7 @@ export class UsbPeripheral implements Peripheral {
await snooze(100);
}
logger('Timeout while try to read from buffer');
reject(new Error('Timeout while try to read from buffer'));
});
}

View File

@@ -0,0 +1,13 @@
import { decodeCommandResponse } from '../../../src/util/usb/decode-command-response';
describe('decodeCommandResponse', () => {
it('should parse the command', () => {
const arr = '03 00 0c 00 a0 00 00 02 00 00 00 00 c1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00'
.split(' ');
const buffer = Buffer.from(arr);
const response = decodeCommandResponse(buffer);
expect(response.code).toEqual(0);
expect(response.tag).toEqual(0);
});
});