Merge branch 'master' of github.com:UltimateHackingKeyboard/agent into finalize-usb-protocol

This commit is contained in:
László Monda
2017-12-12 00:15:15 +01:00
3 changed files with 46 additions and 41 deletions

View File

@@ -6,67 +6,80 @@ export class HardwareConfiguration {
signature: string; signature: string;
@assertUInt8 @assertUInt8
dataModelVersion: number; majorVersion: number;
@assertUInt8 @assertUInt8
deviceId: number; minorVersion: number;
@assertUInt8
patchVersion: number;
@assertUInt8 @assertUInt8
brandId: number; brandId: number;
@assertUInt8
deviceId: number;
@assertUInt32 @assertUInt32
uuid: number; uniqueId: number;
isVendorModeOn: boolean;
isIso: boolean; isIso: boolean;
hasBacklighting: boolean;
fromJsonObject(jsonObject: any): HardwareConfiguration { fromJsonObject(jsonObject: any): HardwareConfiguration {
this.signature = jsonObject.signature; this.signature = jsonObject.signature;
this.dataModelVersion = jsonObject.dataModelVersion; this.majorVersion = jsonObject.majorVersion;
this.deviceId = jsonObject.deviceId; this.minorVersion = jsonObject.minorVersion;
this.patchVersion = jsonObject.patchVersion;
this.brandId = jsonObject.brandId; this.brandId = jsonObject.brandId;
this.uuid = jsonObject.uuid; this.deviceId = jsonObject.deviceId;
this.uniqueId = jsonObject.uniqueId;
this.isVendorModeOn = jsonObject.isVendorModeOn;
this.isIso = jsonObject.isIso; this.isIso = jsonObject.isIso;
this.hasBacklighting = jsonObject.hasBacklighting;
return this; return this;
} }
fromBinary(buffer: UhkBuffer): HardwareConfiguration { fromBinary(buffer: UhkBuffer): HardwareConfiguration {
this.signature = buffer.readString(); this.signature = buffer.readString();
this.dataModelVersion = buffer.readUInt16(); this.majorVersion = buffer.readUInt8();
this.deviceId = buffer.readUInt8(); this.minorVersion = buffer.readUInt8();
this.uuid = buffer.readUInt32(); this.patchVersion = buffer.readUInt8();
this.brandId = buffer.readUInt8(); this.brandId = buffer.readUInt8();
this.deviceId = buffer.readUInt8();
this.uniqueId = buffer.readUInt32();
this.isVendorModeOn = buffer.readBoolean();
this.isIso = buffer.readBoolean(); this.isIso = buffer.readBoolean();
this.hasBacklighting = buffer.readBoolean();
return this; return this;
} }
toJsonObject(): any { toJsonObject(): any {
return { return {
signature: this.signature, signature: this.signature,
dataModelVersion: this.dataModelVersion, majorVersion: this.majorVersion,
deviceId: this.deviceId, minorVersion: this.minorVersion,
patchVersion: this.patchVersion,
brandId: this.brandId, brandId: this.brandId,
uuid: this.uuid, deviceId: this.deviceId,
isIso: this.isIso, uniqueId: this.uniqueId,
hasBacklighting: this.hasBacklighting isVendorModeOn: this.isVendorModeOn,
isIso: this.isIso
}; };
} }
toBinary(buffer: UhkBuffer): void { toBinary(buffer: UhkBuffer): void {
buffer.writeString(this.signature); buffer.writeString(this.signature);
buffer.writeUInt16(this.dataModelVersion); buffer.writeUInt8(this.majorVersion);
buffer.writeUInt8(this.deviceId); buffer.writeUInt8(this.minorVersion);
buffer.writeUInt8(this.patchVersion);
buffer.writeUInt8(this.brandId); buffer.writeUInt8(this.brandId);
buffer.writeUInt32(this.uuid); buffer.writeUInt8(this.deviceId);
buffer.writeUInt32(this.uniqueId);
buffer.writeBoolean(this.isVendorModeOn);
buffer.writeBoolean(this.isIso); buffer.writeBoolean(this.isIso);
buffer.writeBoolean(this.hasBacklighting);
} }
toString(): string { toString(): string {
return `<HardwareConfiguration signature="${this.signature}">`; return `<HardwareConfiguration signature="${this.signature}">`;
} }
} }

View File

@@ -64,7 +64,7 @@ export class UserConfigEffects {
const hardwareConfig = new HardwareConfiguration(); const hardwareConfig = new HardwareConfiguration();
hardwareConfig.fromBinary(UhkBuffer.fromArray(data)); hardwareConfig.fromBinary(UhkBuffer.fromArray(data));
if (hardwareConfig.uuid > 0) { if (hardwareConfig.uniqueId > 0) {
return hardwareConfig; return hardwareConfig;
} }
return null; return null;

View File

@@ -3,36 +3,28 @@ const {HardwareConfiguration, UhkBuffer} = require('uhk-common');
const {EepromTransfer, getTransferBuffers, UhkHidDevice, UsbCommand} = require('uhk-usb'); const {EepromTransfer, getTransferBuffers, UhkHidDevice, UsbCommand} = require('uhk-usb');
const Logger = require('./logger'); const Logger = require('./logger');
if (process.argv.length < 3) { if (process.argv.length < 2) {
console.log(`use: write-hca <layout> <manufactureId> console.log(`use: write-hca {iso|ansi}`);
- layout: iso or ansi
- manufactureId: max 32 bit integer
`);
process.exit(1); process.exit(1);
} }
const layout = process.argv[2]; const layout = process.argv[2];
if (layout !== 'iso' && layout !== 'ansi') { if (layout !== 'iso' && layout !== 'ansi') {
console.log('Invalid layout. Layout should be on of: iso, ansi'); console.log('Invalid layout. Layout should be either iso or ansi');
process.exit(1); process.exit(1);
} }
const uuid = Number.parseInt(process.argv[3]);
if (isNaN(uuid)) {
console.log('Manufacture Id is not a integer');
process.exit(1);
}
const hardwareConfig = new HardwareConfiguration(); const hardwareConfig = new HardwareConfiguration();
hardwareConfig.signature = 'UHK'; hardwareConfig.signature = 'UHK';
hardwareConfig.dataModelVersion = 0; hardwareConfig.majorVersion = 1;
hardwareConfig.deviceId = 1; hardwareConfig.minorVersion = 0;
hardwareConfig.uuid = uuid; hardwareConfig.patchVersion = 0;
hardwareConfig.brandId = 0; hardwareConfig.brandId = 0;
hardwareConfig.deviceId = 1;
hardwareConfig.uniqueId = Math.floor(2**32 * Math.random());
hardwareConfig.isVendorModeOn = false;
hardwareConfig.isIso = layout === 'iso'; hardwareConfig.isIso = layout === 'iso';
hardwareConfig.hasBacklighting = false;
const logger = new Logger(); const logger = new Logger();