Merge branch 'master' of github.com:UltimateHackingKeyboard/agent
This commit is contained in:
554
package-lock.json
generated
554
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -62,7 +62,7 @@
|
||||
"jasmine-node": "3.0.0",
|
||||
"jasmine-ts": "0.3.0",
|
||||
"jsonfile": "4.0.0",
|
||||
"lerna": "3.16.1",
|
||||
"lerna": "3.16.4",
|
||||
"lodash": "4.17.15",
|
||||
"node-hid": "0.7.8",
|
||||
"npm-run-all": "4.0.2",
|
||||
@@ -75,7 +75,7 @@
|
||||
"stylelint": "10.0.0",
|
||||
"svg-sprite": "1.5.0",
|
||||
"ts-loader": "5.3.3",
|
||||
"ts-node": "7.0.1",
|
||||
"ts-node": "8.3.0",
|
||||
"tslint": "5.18.0",
|
||||
"typescript": "3.5.3",
|
||||
"webpack": "4.29.5",
|
||||
|
||||
@@ -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'));
|
||||
});
|
||||
}
|
||||
|
||||
13
packages/kboot/test/util/usb/decode-command-response.spec.ts
Normal file
13
packages/kboot/test/util/usb/decode-command-response.spec.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user