Merge branch 'master' of github.com:UltimateHackingKeyboard/agent

This commit is contained in:
László Monda
2019-07-30 22:24:00 +02:00
4 changed files with 216 additions and 367 deletions

554
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -62,7 +62,7 @@
"jasmine-node": "3.0.0", "jasmine-node": "3.0.0",
"jasmine-ts": "0.3.0", "jasmine-ts": "0.3.0",
"jsonfile": "4.0.0", "jsonfile": "4.0.0",
"lerna": "3.16.1", "lerna": "3.16.4",
"lodash": "4.17.15", "lodash": "4.17.15",
"node-hid": "0.7.8", "node-hid": "0.7.8",
"npm-run-all": "4.0.2", "npm-run-all": "4.0.2",
@@ -75,7 +75,7 @@
"stylelint": "10.0.0", "stylelint": "10.0.0",
"svg-sprite": "1.5.0", "svg-sprite": "1.5.0",
"ts-loader": "5.3.3", "ts-loader": "5.3.3",
"ts-node": "7.0.1", "ts-node": "8.3.0",
"tslint": "5.18.0", "tslint": "5.18.0",
"typescript": "3.5.3", "typescript": "3.5.3",
"webpack": "4.29.5", "webpack": "4.29.5",

View File

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